Basic data types
The basic data types of Python are as follows:
1. int ==> integer. Used primarily for mathematical operations
2. str ==> string, can save a small amount of data and do the corresponding operation
3. Bool==> judgment True, false
4. list==> stores large amounts of data. Use [] to denote
5. Tuple=> tuples, can not be changed with () indicated
6. Dict==> dictionary, save key value pair, same can save large amount of data
7. Set==> collection, saving large amounts of data. Can not be repeated. In fact, it is not the dict to save value
Two. Integer (int)
All integers in Python3 are of type int. But in Python2 if the amount of data is larger. A long type is used. There is no long type in Python3
An integer that can be manipulated:
Bit_length (). Calculates the length of the binary code that an integer occupies in memory
A = 5== a.bit_length ()print(s)
Three. Boolean value (BOOL)
The value is only true, False. BOOL value does not operate.
About the conversion problem before the different types,
STR----> INT
int (str)
int----> str
STR (int)
BOOL----> str
STR (BOOL)
BOOL---> int
Int (True) This value is 1
Int (False) This value is 0
STR (BOOL)
STR-----> BOOL
BOOL (STR) Note here that only the null character is false other characters are true for example "" This is false, or S = None This is also false
In addition to the problem of NULL here, not only string, empty tuple, empty list is False
such as bool ([])------> False
Features: null: False. Non-null: True
int-----> BOOL
BOOL (int) Note here that 0 is false and the other value is true
(True and 1 efficiency issues: 1 efficiency is high.)
Example:
while 1: print(" haha ")
Classic examples:
Loop through the user name and jump out of the program when the user enters the ENTER key.
while True: = Input (" Please enter the user's name:") if not name : break Else: print(name)
Four. String
Index (strings can take values from the string based on the index)
Example:
" Abcdefghijk " Print (S[0]) Print (s[5]) Print (S[-1]) # The first of the countdown Print (S[-5]) # Bottom Fifth .
Here's what to note:
Positive is starting from 0, reverse is starting from 1
slices (use subscript index to intercept part of the string)
Example:
Python Learning Chapter III