"" "
Data type {01: numeric {01: int (integer)
{02: float (float type)
Boolean type {{02:01: True (True)
{02: False (False)
{03: STR (character)
{04: list (list) []
{05: the tuple (a tuple) ()
{06: set (set)
{07: dict (dictionary)
"" "
"" "
1. According to the different variables to store different data types of
2. Verify that the data what type - test data type - the type (data)
"" "
Num1=1
Print (type (num1))
Num2=1.1
Num3='hello world'
Num4=True # bool type only True and False
Num5=[10, 30] # brackets [] - a list
Num6=(10, 20) # parentheses () and more than one number - tuple
Num7={10} # curly braces {} - set
Num8={' num ':' TOM ', 'age', '18'} # with variable name {' name ':' values'} type exist dict
Print (type (num2))
Print (type (num3))
Print (type (num4))
Print (type (num5))
Print (type (num6))
Print (type (num7))
Print (type (num8))
"" "
2: string format commonly used symbols % s
% f floating-point
% d signed decimal integer
General character % c
The % u unsigned decimal integer
% o octal integer
% x hexadecimal integer (lowercase ox)
% X hexadecimal integer (uppercase OX)
% e scientific notation (lower case 'e')
% E scientific notation (capital ")
% % f g + % e
% % f G + % E
@ % d,,, said integer output display digits, not enough to 0 completion, beyond the digits are the same output
@ % 2 f,,, said display the decimal places
"" "
"" "
1, prepare data
2, the formatting output
"" "
Age=10
Name='Tom'
Weight=75.5
Sth_id=1
Sth_id2=1000
# 1. This year I'm x years old age
Print (' this year I aged 6 d is % '% age)
# 2. My name is x
Print (' my name is % s' % name)
# 3. My weight is kg x
Print (' kilograms. My weight is % 2 f '% weight)
4.1 my student number is # 001
Print (' my student id is % 3 d % sth_id2)
# 5. My name is x, my age is y
Print (' my name is % s, my age is % d '% (name, age))
# 6: my name is x, my age is y, z is kg, student id is n
Print (' my name is % s, my age is % d, weight is % 2 f kilograms, student id is % 3 d '% (name, age, weight, sth_id))
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Expand # % s
# * * my name is x, my age is y, n is kg
Print (' my name is % s, my age is % s, % s is kg '% (name, age and weight))
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a formatted string in addition to % s, you can also write to f (expression) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# * * my name is x, my age is y
# format (f '* * * *} {expression)
Print (' my name is % s, my age is % d '% (name, age))
Print (f 'my name is {name}, my age is {age}, {age + 1}' next year)
"" "
1.3 escape character
* * * * \ n -- -- -- -- --
a new line* * * * \ t -- -- -- -- -- the location of the tabulation a TAB key -- -- -- -- --
4 Spaces"" "
Print (' hello ')
Print (' world ')
Print (' hello \ nworld ')
Print (' \ tabcd ')
"" "
In Python, print (), the default built-in end="\ n" end of the line feed,
So lead to every two print () line show users can directly according to the requirement changes end
"" "
Print (" hello ", end="\ n")
Print (' world ')
Print (" python ", end="\ t")
Print (' hello ')
Print (" hello ", end="-")
Print (' asdfghjkl ')
# grammar -- -- -- -- -- -- -- -- -- input (" message ")
"" "
1. When the program is input, waiting for user input, the input to continue after the completion of execution down
2. In python, input after receiving user input, generally stored in the variable, just use the
3. In python, input will receive to any user input the data as string handling
"" "
Password=input (" please enter your password:)
STR=input ()
Print (STR)
Print (' the password you entered is: % s' % password)
Print (f 'the password you entered is: {password}')
Print (type (password))
"" "
To convert the data types of function
Commonly used
Int x [, base]) -- -- -- -- -- -- -- -- -- will be converted to an integer x
Float (x) -- -- -- -- -- -- -- -- -- -- -- -- -- -- will be converted to a floating point number x
STR (x) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - will object into a string x
The eval (STR) -- -- -- -- -- -- -- -- -- -- -- -- -- used to calculate a valid python expression in the string, and returns an object
Tuple (s) -- -- -- -- -- -- -- -- -- -- -- -- -- -- the sequence s is converted to a tuple
The list (s) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the sequence s is converted to a list
General
Complex (real [, imag]) - create a plural, real for the real component, imag as imaginary part
Repr (x) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- converts the object x expression string
Word (x) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - to convert a character to the corresponding ASCII integer values
"" "
"" "
Num=input (" please enter the number:)
Print (num)
Print (type (num))
Print (type (int (num)))
"" "
Num1=1
Str1='18'
Print (type (float (num1)))
Print (float (num1))
Print (float (str1))
Print (type (STR (num1)))
Print (STR (num1))
List1=[10, 30]
Print (tuple (list1))
T1=(10200300)
Print (list (t1))
Str2='1'
Str3='1.1'
Str4='(100200300)
Str5='[300200100]'
Print (type (eval (str2)))
Print (type (eval (str3)))
Print (type (eval (str4)))
Print (type (eval (str5)))
"" "
1. The arithmetic operator
1.1 +
1.2
1.3 *
1.4/
Aliquot of 1.5//9//4 results of 2
1.6%
Index of 1.7 * * * * 4 result is 16 the 2 * 2 * 2 * 2=16
1.8 () parentheses are used to improve priority
!!!!! Mixed operation priority () is better than * *///% than + -
Complex operator
2.2.1=
2.1.1 single variable assignment num=1
Print (num)
2.1.2.1 multiple variable assignment num1 float1, str1=10,0.5, 'hello world'
Print (num1)
Print (float1)
Print (str1)
2.1.2.2 multivariate fu same value a=b=10
Print (a)
Print (b)
3. The compound assignment operator
3.1 +=addition assignment operator c +=a & lt;==& gt; C=c + a
3.2=subtract the assignment operator=c - a & lt;==& gt; C=c - a
3.3 the assignment operator c * *=method=a & lt;==& gt; C=c * a
3.4/the assignment operator=division c/=a & lt;==& gt; C=c/a
Divided exactly by 3.5//=assignment operator//c=a & lt;==& gt; C=c//a
More than 3.6%=take the assignment operator c %=a & lt;==& gt; C=c % a
3.7=power assignment operator c * * * *=a, & lt;==& gt; C=c * * a
!!!!! C=10
C +=1 + 2
Print (c)
D=10
D *=1 + 2
Print (d) 1 + 2 * 3 d on the first d=30
To calculate the compound assignment operator behind, then the compound assignment operators
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull