Python3 Study (i)

Source: Internet
Author: User

Basic grammar Python3 is not compatible, some syntax is not the same as python2.x, the IDLE shell Editor, shortcut keys: alt+p, the previous history input, alt+n the next historical input content. #idle中按F5可以运行代码

BIF--Built in functions query Python how many BIF built-in functions are available: Dir (__builtins__)

[' Arithmeticerror ', ' assertionerror ', ' attributeerror ', ' baseexception ', ' blockingioerror ', ' brokenpipeerror ', ' Buffererror ', ' byteswarning ', ' childprocesserror ', ' connectionabortederror ', ' connectionerror ', ' Connectionrefusederror ', ' connectionreseterror ', ' deprecationwarning ', ' eoferror ', ' ellipsis ', ' EnvironmentError ', ' Exception ', ' False ', ' fileexistserror ', ' filenotfounderror ', ' floatingpointerror ', ' futurewarning ', ' generatorexit ', ' IOError ', ' importerror ', ' importwarning ', ' indentationerror ', ' indexerror ', ' interruptederror ', ' isadirectoryerror ' , ' Keyerror ', ' keyboardinterrupt ', ' lookuperror ', ' memoryerror ', ' nameerror ', ' None ', ' notadirectoryerror ', ' Notimplemented ', ' notimplementederror ', ' oserror ', ' overflowerror ', ' pendingdeprecationwarning ', ' PermissionError ', ' Processlookuperror ', ' referenceerror ', ' resourcewarning ', ' runtimeerror ', ' runtimewarning ', ' stopiteration ', ' SyntaxError ', ' syntaxwarning ', ' systemerror ', ' systemexit ', ' taberror ', ' timeouterror ', ' True ', ' TypeError', ' unboundlocalerror ', ' unicodedecodeerror ', ' unicodeencodeerror ', ' unicodeerror ', ' unicodetranslateerror ', ' Unicodewarning ', ' userwarning ', ' valueerror ', ' Warning ', ' windowserror ', ' zerodivisionerror ', ' __build_class__ ', ' __ Debug__ ', ' __doc__ ', ' __import__ ', ' __loader__ ', ' __name__ ', ' __package__ ', ' __spec__ ', ' abs ', ' all ', ' any ', ' ASCII ', ' Bi n ', ' bool ', ' bytearray ', ' bytes ', ' callable ', ' Chr ', ' Classmethod ', ' compile ', ' complex ', ' copyright ', ' credits ', ' Delatt ' R ', ' Dict ', ' dir ', ' divmod ', ' Enumerate ', ' eval ', ' exec ', ' exit ', ' filter ', ' float ', ' format ', ' Frozenset ', ' getattr ', ' GL Obals ', ' hasattr ', ' hash ', ' help ', ' hex ', ' id ', ' input ', ' int ', ' isinstance ', ' issubclass ', ' iter ', ' Len ', ' License ', ' lis T ', ' locals ', ' map ', ' Max ', ' Memoryview ', ' min ', ' Next ', ' object ', ' Oct ', ' Open ', ' ord ', ' pow ', ' print ', ' property ', ' Quit ', ' range ', ' repr ', ' reversed ', ' round ', ' Set ', ' setattr ', ' slice ', ' sorted ', ' staticmethod ', ' str ', ' Sum ', ' super ', ' TUPL E ', ' type ', ' vars ', ' zip ']

Query the usage of built-in functions: Help (function name) such as: Help (str)

helloworld.py

12345678910111213141516171819202122232425 temp =input("input number:")guess =int(temp)ifguess == 8:    print("is 8")else:    print("is 8")    print("tab is useing")print("out game")frist =3second =8third =frist +secondprint(third)str1 ="string1"str2 =" string2"str3 =str1 +str2print(str3)------------------------------inputnumber:8is8out game11string1 string2

The closing sentence does not require a semicolon, after the colon, the carriage return is automatically indented, the TAB key is meaningful, not just the code indentation, the indentation inside belongs to the same logical module. You cannot use the SPACEBAR before the code in a non-logical hierarchy, the TAB key.

The variable does not require a specified type and is automatically converted. Python has no "variable", only "name". Variables are mutable, and variables need to be assigned before they are used. The numbers are added, the strings are stitched, and the strings belong to text.

#前后必须使用同样的单引号或双引号, the characters must be half-width in English. Print (' 5 ' + "8")

#反斜杠可以作为转义字符串, the original string is preceded by R in front of the string and cannot be prefixed with a backslash at the end.

#跨越多行的字符串: Sanchong Quotes string (can be three single quotes or three double quotes), put the content in the middle, can be used as a multi-line comment

12345 print(‘c:\\now I\‘am‘)print(‘‘‘ line1line3‘‘‘)print("hello\n"*3#会打印3次

#注释使用 #, if it is to make explanatory comments, you can use __doc__ str.__doc__ #输出str函数的文档描述内容 python is a feature that does not delimit blocks of code by curly braces {}, but through ... ' __doc__ ', ' __eq__ ', ' __ Format__ ', ' __ge__ ', ' __getattribute ...

============================================

123456789101112131415161718192021222324252627 #引入外部模块 import random#random模块,randint(开始数,结束数) 产生整数随机数importrandomsecret =random.randint(1,10)temp =input("请输入一个数字\n")guess =int(temp)count =0;whileguess != secret: #猜错的时候才进入循环条件    ifcount ==0andguess > secret:        print("猜大了")    ifcount ==0andguess < secret:        print("猜小了")    temp =input("请重新输入\n"#需要在判断之前让用户输入,否则猜对了就直接退出了    guess =int(temp)    count +=1 #不能使用count++这种方式    ifcount > 2:        print("猜错4次自动退出了")        break#退出循环    ifguess ==secret:        print("恭喜,你猜对了")        print("猜对了也就那样")    else:        ifguess > secret:            print("猜大了")        else:            print("猜小了")print("游戏结束")

Python3 Study (i)

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.