Tag: Represents variable one input Boolean string different class state decimal
Data type
1. What is a data type?
The value of the variable is the data we save, so the data type refers to the kind of variable value
2. Why are data classified?
Variable values are used to preserve the state of the real world, so for different states, you should use different types of data to represent
3. Data type classification?
①. Integer int
1. Function: Indicates the person's age, number, rank
2. Definition: Age =---> age = Int (18)
Print (ID (age)) print (type) print (age)
②. Float type float
1. Function: Data with decimals
2. Definition: Salary = 3.1---> salary = float (3.1)
Print (ID (salary)) print (Type (salary)) print (salary)
③. String str
1. Function: Describe the nature of the state, such as: People's names
2. Definition: A string of characters contained within single quotation marks, double quotes, and three quotation marks
Name = ' Egon '---> name = str (' Egon ')
3. How to use: strings can only be added or multiplied
④. Listing List
1. Function: Used to access multiple values
2. How to define: separate multiple values of any type with commas within []
Hobbies = [' read ', ' Run ']
3. How to: Value by index, index starting from 0
Print (Hobbies[0])
⑤. Dictionary Dict
1. Function: Used to access multiple values, press Key:value access, key to describe value
2. How to define: separate elements with commas within {}, each element is Key:value format, where value can be any type, key is mostly string type
Dic = {' name ': ' Egon ', ' Age ': 18}
3. How to use: Print (dic[' name ')
⑥. Boolean bool
1. Function: Used to judge the right and wrong true False
The value of all data types is itself a Boolean value, that is, all data types can be treated as conditions.
where, 0,none and null are three classes of Boolean values false
Interacting with users
Input in Python3 will save any content entered by the user into a string type
Name = input (' >>> ')
Formatted output
Name = ' Egon ' age = 18
Print (' Ma name is%s My age is%s '% (name, age))
%s can actually receive any type of value
And%d can only receive integer types
Basic operators
+ Plus-minus * multiply/divide
% modulo 10%3 equals 1//Take divisible 9/2 equals 4
* * Power 10**2 equals 100
= = equals! = Not equal to
Compare sizes between lists, only values corresponding to the same location are of the same type
+ = age + = 1---> age = Age + 1
Focus: Chained Assignment a=b=c=d=10
Cross-assignment x, y = y,x---> tem = x x = y y = tem
Decompression of the variable value L = [' A ', ' B ', ' C '] x, y, z = l--->x = l[0] y = l[1] z = l[2]
Python Learning day Three: data type, interactive, formatted output, basic operator