in 0.Python, int denotes integral type
BOOL: Boolean type
float: Float type
STR: String type
1. Why are Boolean type (bool) True and false denoted by 0 and 1 respectively?
The computer only knows the binary, because the binary has only two numbers 0 and 1, so it is appropriate to use 0 and one, because there is no need to waste resources in the process of conversion
2. Use int () to convert a decimal number to an integer, the result of rounding up or down rounding?
Rounding down
3. The human mind is a customary "rounding" method, what is the way to make an int () rounded up in the same way?
Plus 0.5
Example: 8.3----8,int (8.3+0.5) =8
8.6----9,int (8.6+0.5) =9
4. Take the type of a variable, the video shows you can use type () and ininstance (), which do you prefer to use?
Type () directly returns the types of an input variable
Ininstance () Returns a variable that is compared to the type of another variable, returns true if it is a uniform type, or false if it is different
5.python3 can give the variable a name in Chinese, do you know why?
Python3 source file By default using UTF-8 encoding (support Chinese), which makes the code is legitimate
Do it
0.
S.isalnum () All characters are numbers or letters, return True, otherwise False
S.isalpha () All characters are letters, returns true for true, otherwise False
S.isdigit () All characters are numeric and true returns True, otherwise False is returned
S.islower () All characters are lowercase, true is true, otherwise False is returned
S.isupper () All characters are uppercase, returns true for true, otherwise False
S.istitle () All words are capitalized first, true returns false, otherwise true
S.isspace () All characters are white space characters, true is true, otherwise False is returned
6. Determine whether a given year is a leap years
Write yourself: Need to improve places less than 0 and greater than 3000
While True:
temp = input (' Enter year ')
While Temp.isspace ():
Temp=input (' Input wrong, please re-enter ')
year = Int (temp)
If Year<0 or year>3000:
Print (' Enter year not valid ')
Else
If year%4==0 and year%100!=0 or year%400==0:
Print (' Leap year ')
Else
Print (' Not a leap year ')
Elementary Turtle's Code:
temp = input (' Enter a year: ') and not Temp.isdigit (): temp = input ("Sorry, your input is wrong, please enter an integer:") year = Int (temp) If year/400 = i NT (year/400): Print (temp + ' is a leap year!) ') Else: if (YEAR/4 = = Int (YEAR/4)) and (year/100! = Int (year/100)): Print (temp + ' is a leap year!) ' Else: Print (temp + ' is not a leap year!) ‘)
Little Turtle Python Fifth talk