We know that the data stored in the computer are all binary numbers, so what is the data type? What is it good for?
For the 8-bit binary number 0 1 000 0 0 1, if interpreted as an integer, it is 65; if interpreted as an ASCII character, it is the letter A. The visible data type is the interpretation method for binary numbers. The same binary data, with different interpretation methods, represents different meanings, so if there is no data type, the binary numbers in the computer can only be a bunch of meaningless things.
The first thing we need to understand are the three types of numbers, booleans, and strings.
Number type
There are three types of numbers commonly used in Python:
String type
Example 1:
boolean type
In fact, Python's Boolean type is an extension of the integer type (int), that is, True can be used as an integer 1 and False as 0. And in all numeric types, except the 0 value (integer 0, floating-point 0.0, complex 0+0j) is False, all other values are True.
String concatenation
string copy
1. Question:
2. The first solution and the problems existing in the method:
3. Better solution:
4. Better solution procedures and results:
Swap values of two variables
The type() function determines the type of the variable
Although it is possible to judge the data type of a variable by the appearance of the data, it is sometimes difficult to see the appearance of the data, and the variable may also change the type in multiple assignments, so Python also provides a variable type judgment function type(). Python variables do not need to declare a type, nor do they have a fixed type, that is, the type of the variable is determined by its current value, so in some cases, the type() function is required to determine the type of the variable.
Call method:
Calling example:
Print() multi-parameter call mode: In addition to one number or string, the parameter of print () can also be multiple numbers or strings separated by English commas (,) , as in the above code. There is at least 1 space between the items of the printed result, and the string concatenated with the plus sign (+) is printed without spaces, as shown in the following figure.
type() returns a string parsing: The content in <> is the type description, class represents the type, 'int' is an integer, 'float' is a float, 'bool' is a boolean, and 'str' is a string .
in conclusion:
The data type of a variable is determined by the stored data.
practise:
first question
Question 2
Question 3
Question 4
Question 5
Question 6
Python blue bridge and other test level two: variables and assignment operators
Python Blue Bridge and other test level one: Arithmetic operators
Python Blue Bridge and other test level 5: printing, annotation and documentation
Python Blue Bridge and other test level 4: Python programming environment
Python Blue Bridge and other test level 3: Why use Python as an introduction to code programming
Python Blue Bridge and other test level two: a brief history of programming language development
One of the first level of the Python Blue Bridge test: a brief history of computer development
"Five Planetology Programming 0.5.1" software introduction and Python introduction
Xuesi Camp offers online programming courses based on the Bluebridge STEM86 platform , welcome to join : >>> Scratch (graphical programming)
>>>Python (code programming)
>>>C++ (specialized code programming).
Open https://xuesiying.stem86.com to register, then add WeChat 13729135043, indicate "Blue Bridge****", **** is the last four digits of the registered mobile phone number.
For more learning materials, please open the "Xuesi Camp" synchronization website: http://5xstar.com