variable
Variable definition:
In the process, sometimes we need two data summation, then how to do it?
We analogies about real life, such as going to the supermarket to buy things, we often need a basket, used to store items until all items are buying is completed, you can checkout at the cash register
If a program requires data to two or more data summing, then it is necessary to store these data to stand, and then they can be added together
In python, a data storage, requires called variable things, the following example:
num1 is a variable, like a small basket
num2 is also a variable
ret = num1 + num2 # num1 and num2 data two "basket" in the accumulated, then into variable ret
Description:
The so-called variable , can be understood as basket, if you need to store more data, the easiest way is to have a number of variables, of course you can also use a
Procedure is used to process the data, and the variable is used to store data
Type of the variable
View variable data types
How do I know the type of a variable of it?
In python, as long as the definition of a variable, and it has data, then its type has been identified, we do not need the developer's initiative to explain its type, the system will automatically identify
You can use type (variable's name), to see the type of a variable
Identifier
Life identifier
What is the identifier?
Some of the symbols and names of developers in a program custom
Identifier own definition, such as variable names, function names, etc.
Identifier naming rules:
- Identifier can only consist of letters, underscore "_" numbers
- Identifiers can not begin with a number
- Identifier can not use the keyword (keyword not the same name in python), but may contain critical
Identifier naming suggestions:
Identifier naming should "see to know the name meaning"
python keywords
python some of the special features of the identifier, which is called keyword
Keyword, python is already in use, so do not allow developers to define their own name and the same keywords as identifiers
Think about what substandard following identifiers
if、name、and、my_list、my_list1、from#1、age、2list、as、True、wetyui、height、my_log、qwe&qwe
Identified by letters, underscores and numbers, and the numbers can not start, must be unique keyword
python identifier is case sensitive
Example: BaoBao not equal baobao, bao not equal Bao
Identifier naming
Underline:
There is also a nomenclature with an underscore "_" to connect all the words, for example:
my_list、user_name
Identifier naming
Hump nomenclature:
Small camel nomenclature (lower camel case): the first word beginning with a lowercase letter; the first letter of the second word is capitalized, for example: myName, myList
Large camel nomenclature (upper camel case): the first letter of each word in capital letters are used, for example: UserName, FirstName, LastName
Export
Life in the output:
Software output:
python output variables:
Formatted output
The purpose of formatting operation:
For example, we have the following code:
Think about it: when the output of age, with a number of "I am xx years old," and it can simplify procedures? ? ?
A: The output format can be done
Formatted output
What is formatted output, see the following code:
Formatted output
In the program, such as% saw operator, the output of which is formatted in python
The formatted output common format symbols
The formatted output format common practice notation
The general format identifier formatted output Examples Introduction
The formatted output transducer output line
Wrap output: when output if there \ n So, at this time \ n after the content is displayed in another row
as the picture shows:
Entry
When we withdraw money before the bank ATM machine, be sure to enter the password, is not it?
So how can let the program know what we just entered it? ?
We should know, if you want to complete the ATM machine to withdraw money this thing, you need to enter data start with a keyboard, and then save with a variable, is not it easier to understand? ? ?
However, the input python2.x and python3.x or differentiated?
python2.x input is such that: raw_input ()
python3.x input is such that: input ()
Python3.x here for an example:
operation result:
input in python interactive environment () function demonstrates:
input () accepts input expression and the result of the expression is assigned to the left operand
Precautions:
python3 version does not raw_input () function, only input () and python3 in input () and raw_input () function accepts the same type are to str
Operators
python supported several operators
- Arithmetic operators
- Assignment Operators
- Compound assignment operators
Arithmetic operators
Below a = 10, b = 20 Example calculated
Case presentation arithmetic operators
Assignment Operators
python interactive environment case presentations
Compound assignment operators
Data type conversion
Common data type conversion
python interactive environment case presentations