1, the most basic IO statement
Name=input ()
Print (' Hello, ', name)
2, Python also allows to use R ' ' to indicate that the string inside of ' is not escaped by default
Print (' \\\t\\ ')
Print (R ' \\\t\ ')
3, null value is expressed as none, but not understood as 0. Because 0 is meaningful.
4. Java is a static language, and variable types must be specified when defining variables. Python is a dynamic language and more flexible.
5. a= ' abc '
B=a
A= ' XYZ '
Print (b)
Indicates that the variable B points to the data that the variable a points to, and the result of print variable B is ' abc '.
6, ASCII encoding is a byte, Unicode encoding is two bytes, UTF-8 encoding compared to save space.
Unicode encoding is used uniformly in computer memory and converted to UTF-8 encoding when saved to hard disk or transmitted.
In versions above Python3, the strings are encoded in Unicode.
7.
>>> s1=72
>>> s2=85
>>>r= (S2-S1)/float (S1) *100
>>> print ('%.1f%% '%r)
18.1%
8, the tuple is immutable, try to use a tuple instead of list. When defining a tuple, the elements of a tuple must be determined.
9.
10.
11.
Practice
Xiao Ming is 1.75 tall and weighs 80.5kg. Please help Xiao Ming calculate his BMI according to the BMI formula (weight divided by the square of height) and according to the BMI Index:
- Less than 18.5: too light
- 18.5-25: Normal
- 25-28: Overweight
- 28-32: Obesity
- Above 32: Severe obesity
To if-elif
determine and print the result:
Height=float (Input (' Please enter height '))
Weight=float (Input (' Please enter weight '))
bmi=weight/(height**2)
If bmi<18.5:
Print (' BMI is%.2f, too light '%bmi)
Elif bmi>=18.5 and bmi<=25:
Print (' BMI is%.2f normal '%bmi)
Elif bmi>25 and bmi<=28:
Print (' BMI is%.2f, overweight '%bmi)
Elif Bmi>28and bmi<=32:
Print (' BMI is%.2f, fat '%bmi)
Else
Print (' BMI is%.2f, severely obese '%bmi)
Python Learning notes (i)