SoFunction
Updated on 2024-11-21

Python's Input, Output and Identifiers in Detail

I. Identifiers

What is an identifier?

An identifier is a symbol used to identify an entity. In programming languages, an identifier is a collection of valid strings used as names in a computer language. Identifiers are the names that users use when programming, variables, constants, functions, and statement blocks also have names, and their names become identifiers.

Notes on identifiers:

1. It consists of numbers, letters, and underscores, and cannot begin with a number, the code is as follows:

1_username = 'Lisi' # Identifiers that begin with a number will simply report an error

2. Strictly case-sensitive

name = 'Ander LiWorking on the code.
print(Name) # It's a direct error.

3. Cannot use keywords - words with special meanings: if / for / while / else, etc.

4. Keywords cannot be used as variable names

5. Doing what the name implies

name = 'Zhang San' #Name
age = 19      # Age
weight = 80   #Weight
print(name,age,weight)

Naming should be standardized:

  • Little Hump Nomenclature : Initials in lowercase, rest of initials in uppercase ==>(userNameAndPassword)
  • Big Hump Nomenclature : Capitalize the first letter of each word ==>(PersonModel)
  • Use underscores to connect :user_name_and_password

The following two points need to be noted:

  • Underscore variable, function, and module names in Python.
  • Class names in Python use big-hump nomenclature

II. input

() Inside the parentheses, write the message.

2. Define a variable that can save user inputs

3. No matter what the user enters, the variable saves the result as a string

Use the input built-in function to accept input from the user

5. Note: strings can not be added to the number (integer), otherwise an error will be reported!

III. Print (output)

The sep parameter is used to indicate which character is used to separate each value in the output, the default is to use space as the separator.

sep=' ',:There's a space in the middle.(for example:print('hello','good','yes','hi',sep='+')

endAfter executing a print statement, the next character to be output defaults to \n for a newline.

print('hello','good','yes','hi',end="-----------")

summarize

That's all for this post, I hope it was helpful and I hope you'll check back for more from me!