Python Learning Note 1

Source: Internet
Author: User

Guess the age to play

##!/usr/bin/python3#-*- coding:utf-8 -*-age = 24counter = 0for i in  range:     print ('-->counter: ', counter)     if counter  < 3:      num = int (Input ("QINGSHURU&NBSP;:"))        if num == age:          print ("huanying")          break       elif num > age:         print ("Tai  da ")       else:         print ("Tai xiao")     else:      continue_num= input ("Ni  xiang jixu ma:  ")       if continue_num ==  ' Y ':          counter = 0          Continue      else:         print (" Bye ")          break    counter =  Counter + 1


Login

#!/usr/bin/python3#-*-coding:utf-8-*-import getpassfor i in range (3): if I < 3:user = input ("Please enter user name:") passwor D = Getpass.getpass ("Please enter password:") if user = = "Chenhao" and Password = = "Chen": Print ("Welcome") Break Else:print ( "User name or password error") Else:print ("Too many inputs")


String formatted output

1234 name ="alex"print"i am %s "% name #输出: i am alex

PS: string is%s; integer%d; floating-point number%f

String Common functions:

    • Remove whitespace

    • Segmentation

    • Length

    • Index

    • Slice

#!/usr/bin/env python# -*- coding: utf-8 -*- importsysprint(sys.argv)#输出$ python test.py helo world[‘test.py‘‘helo‘‘world‘]  #把执行脚本时传递的参数获取到了

  

Os

123456 #!/usr/bin/env python# -*- coding: utf-8 -*-importos os.system("df -h"#调用系统命令

A complete combination.

123 importos,sysos.system(‘‘.join(sys.argv[1:])) #把用户的输入的参数当作一条命令交给os.system来执行


This article is from "Hao son of ▁ Yun's finger licking" blog, please be sure to keep this source http://chenhao6.blog.51cto.com/6228054/1863837

Python Learning Note 1

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.