The first section of Python learning notes

Source: Internet
Author: User

First, HelloWorld

#! /usr/bin/env python
#-*-Coding:utf-8-*-

Print ("helloworld!")


Second, user interaction
#!/usr/bin/env python #_*_coding:utf-8_*_ name  =  input ( "What is your name?" ) print ( "Hello "  name )

When entering a password, if you want to be invisible, you need to take advantage of the Getpass method in the Getpass module, namely: importgetpass

# 将用户输入的内容赋值给 name 变量 pwd  =  getpass.getpass( "请输入密码:" )    # 打印输入的内容 print (pwd) #!/usr/bin/env python # -*- coding: utf-8 -*-username = input ("username:")Password = getpass.getpass ("Password:")print ("Username,password")#在pycharm中会执行不了, but can be performed in a Linux environmentThird, string formatted output name  = "emily" print "i am %s " % name   #输出: i am emily PS: string is%s; integer%d; floating-point number%f Iv. expression If......else #!/usr/bin/env python    # -*- coding: utf-8 -*- _username = ' Emily '_password = ' abc123 'username = input ("Username:")
Password = input ("Password:")

If _username = = Username and _password = = password:
Print ("Welcome user {Name} login ...")
Else
Print ("Invalid username or password!")Five. While statement
A = 30
Count = 0
While Count <3:
b = Int (input ("A:"))
If a = = B:
Print ("Yes")
Break
Elif A>b:
Print ("small")
Else
Print ("Big")
Count +=1
Else
Print ("You have tried too many times. Fuck off ")
VI. For statement
For I in range (10):
Print ('------', i)
For j in Range (10):
Print (j)
If j>5:
Break

The first section of Python learning notes

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.