Day1 Learning Content
- hello World Program
- variable
- user input
- expression if ... else statement
- expression for Loop
- Break and continue
- expression while loop
- formatted output
The first small procedure of international practice
HelloWorld Program for Python language
In the Python language, the end of the statement does not need to be added;
Second, the variable
Python is an explanatory strongly typed dynamic language, meaning that each variable is assigned to it, and the data type is automatically recorded inside the system because Python is a strongly typed language, so in the subsequent run, if the data type of the variable is not changed by casting the data type, The data type of the variable will remain unchanged.
such as name = Gino
In the above assignment code, the variable name is not declared data type but this is legal in Python, Python does not need to declare the data type of the variable as C/c++,java and other languages, and the system automatically records when assigning a value of name to Gino, that is, The system automatically assigns a data type to name based on the data type of the assignment, where the data type of name is string
third, user input, If...else, while loop, break, continue, for Loop
Input in Python is responsible for user input and is the base code for interacting with the user
Example: Small game guessing a person's age, up to three guesses, three times after exiting the program Involves content while looping, if...else, break, In Java if: else is in the format: if (judging condition) {code block} Else {code block} Python uses indentation to represent the format of the statement, indent once, and demote the statement once If judging condition: Print ("XXX") Elif Judging conditions: Else Note that Python is if,elif (equals else if), and else needs a colon at the end: |
While count < 3: #创建while循环 count<3 for expressions to meet this condition loop execution guess_age = Int (input ("Guess Age:"))#input语句获取的所有数据的类型都为字符型String if Guess_age = = Age_of_gino: print ("Yes, you Got it") break #break为结束整个循环 continue to skip this cycle into the next loop elif guess_age > Age_of_gino: print ("Think bigger") Else: print ("Think smaller") count = count + 1 print ("You ' ve guess it {count} time". Format (count=count))#{count} is the formatted output and the output is assigned in the. Fomat
Else: #while不满足条件时执行语句else print ("You have tried too mant times ... fuck off") |
for loop
for I in Range (initial value, end value, step)
Print ("loop", I)
here in the FOR loop the default initial value is 0
If the statement
for me in range (Ten)
print (" loop ", i)
So the output is
loop 0
loop 1
loop 2
...
loop 8
loop 9
altogether 10 times
Four, formatted output
Input variable value
Name = input ("Name:")
age = Int (input ("Age:")) #integer
Print (Type (age) , type ( str))
Job = input ("Job:")
Salary = input ("Salary:")
To create a formatted output
Info2 = " '
--------info of {_name}-----
Name:{_name}
Age :{_age}
Job:{_job}
Salary:{_salary}
". Format (_name=name,
_age=age,
_job=job,
_salary=salary)
The output result is
--------Info of Gino-----
Name:gino
Age:12
Job:it
salary:2000
Python Foundation-day01