Python Foundation Day1

Source: Internet
Author: User

For most programming languages, the first starter code is "Hello world! ", the following code is for using Python output" Hello world! ":

Instance (Python 2.0+)#!/usr/bin/python print "Hello, world!" ; The Python 3.0+ version already has print as a built-in function that correctly outputs "Hello world! The code is as follows:Instance (Python 3.0+)#!/usr/bin/python3Print("Hello, world!" ); A variable cannot be declared with a variable that begins with a number[ "and" ,  ' as ' ,   ' assert ' ,  ' break ' ,  ' class ' ,  ' Continue ' ,  ' def ' ,  ' del ' ,  ' elif ' , < Span class= "crayon-s" > ' Else ' ,  ' except ' ,  ' exec ' ,  ,&NBSP; ' For ', ' from ' ,  ' global ' ,  ' if ' ,  ' import ' ,  ' in ' ,  ' is ' ,  ' Lambda ' ,  ' not ' ,  ' or ' ,  ' pass ' ,  ' print ' ,  ' raise ' ,  ' return ' ,&NBSP; ' Try ', ' while ', ' with ', ' yield '] single quotes, double quotes, and three quotation marks (three single quotes) in Python
Python in the definition of variables when the strings are enclosed in quotation marks, single and double quotation marks no difference, with anything, if there is a single quotation mark inside the string, then you use double quotation marks inside, there are double quotation marks, the outside with single quotation marks, if there are both single and double, then use three quotation marks, Three quotation marks can also be multiple lines of comment code, a single line comment, using #, the code is as follows: msg = "I ' m Sriba." #有单引号, so use double quotes outside info = ' Python comments ues ' # '. ' # #有双引号, so use single quotes outside new_msg = 'i 'm sriba, I love "Python". ' #有双引号和双引号, so use three quotes outside " "The above code is a comment that describes the single quotation mark, double quotation mark, and three quotation marks, which means that the three quotation marks also have multiple lines of comment function." ", input, output


How does python receive user input, use the input function, use Raw_input in Python2, receive a string, output, the first program has been written using print, code into the following:

name=input(' Please enter your name: ') #把接收到的值赋给name变量 Print(name)#输出接收到的输入 If you need to input not Echo Import getpass #导入getpass模块 password = getpass. Getpass(' Please enter your password: ') #接收输入的密码 Print(password) Conditional Judgment
In Python, the conditional judgment uses if else to judge, multi-branch words using if elif ... else, that is, if it's what happens, or how it's going to be. If it rains tomorrow:Then bring the umbrella tomorrow.Else:Tomorrow without an umbrella cycle#while Cyclecount = 0 while Count<: #如果count小于10的话, execute the following code, if it is not less than 3, go to else print (count) if count= =5: break#如果count等于5的话, just end the loop count+ =1 #这个意思是每次循环完, the value of Count is added one, if not added, the condition has been true, the cycle of death, has been constantly circulating else:#这个else是可以不写的, meaning, if the condition is not satisfied, what to do Print(' condition not satisfied ') #for Cyclenames = [' Marry ',' Lily ',' Lilei '] for name in names: if name = = ' Lily ': contiune #如果名字等于lily的话, do not execute continue the following code, and then cycle the next Print(name) else:#for也有个else, but this is generally no one writes it, meaning if the normal cycle is donePrint(' over ')

Python Foundation Day1

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.