1. The first Python program:
Print ("Hello world!") Print Hello world! Run Result: Hello world!
2. Variables
variables, which are used to store things so that they can be called later.
Rules for defining variables:
A variable can be any combination of letters, numbers, or underscores
The first character of a variable cannot be a number
The variable name cannot make the keyword
Name = "Zhang"//Assign the Zhang to name name2 = name//Assign the value of name (Zhang) to name2 name = "Wang" Assign Wang to name print ("My name is", name,name2)//Output "My name is" and name separated by commas running results: My name is Wang Zhang
Add: Single line comment with #, multiline comment with 3 apostrophe or double quotation mark
3. User input
Username = input ("username:")//Enter a user name, assign to username password = input ("Password:") Age = Input ("Age:") salary = InP UT ("Salary") print (username,password,age,salary)//print out the above variables run result: XXL a1! 20 9999
4. Formatted output
username = input ("Username:") age = input ("Age:") job = input ("Job:") salary = input (" Salary: ") info = " //put the format you want to output in three quotes, assign variables ------------------- info of %s -------- ------------ Name:%s Age:%s Job:%s Salary:%s ' % (username,username,age,job,salary) print (info) Run result: username:xxl age:12 job:1 salary:1234 ------------------- info of xxl -------------------- Name:xxl Age:12 Job:1 salary:1234
This article is from the "Technical Achievement Dream" blog, please be sure to keep this source http://xuxiaoliang.blog.51cto.com/10882951/1921264
Python Basics 1 Basic syntax, Process Control