Python Basics 1 Basic syntax, Process Control

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.