Python Basics (ii)

Source: Internet
Author: User

First, comments
Single line comment (line comment)
Start with # and the right is the explanatory text
#+ Comment Content

Multiline comment (block comment)
‘‘‘
Name2=name
Print (' My name is ', name2)
‘‘‘
Second, arithmetic operators
1. Operators

PS in Python * can also be used in strings, the result is a string repetition of the result of a specified number of times 2, priority

First multiplication and then minus
The sibling operator is calculated from left to right
You can use () to adjust the priority of a calculation
* * Power (highest priority)

*,/,%,//multiply, divide, take remainder, take integer

    • -Addition, subtraction

Third, variable
In Python, you do not need to specify a variable's type when defining a variable, but you must assign a value to it

#!/user/bin/env python <--declaration with what interpreter to execute (can not write)
#--Coding:utf-8--<--with UTF-8 encoding python2 need to add
Import Getpass <---Not clear text output the libraries to be imported

#------Character Set Introduction------------------------------------

1.ASCII 8 bit = 1 bytes = 255 symbols
2.GB2312---1980 7,000 multi-character-->GBK----1995 21886 symbol-->gb18030--
--2000 year-->gb2312
3.Unicode per character 2 bytes
4.utf-8 English 1 byte ASCII format, Chinese 3 bytes
5.PYTHON3 is encoded by default in Utf-8, Python2 is ASCII-encoded by default

#--------------------input ()--Input------------------

1.python3-->input () What to type
What to type 2.python2-->raw_input
3. The default input type is string and requires a specific type to be converted

Name2=input (' name: ') #python3-->input () What to type
Password=getpass.getpass (' Password: ') #密文输入
Print (' Password:----', password)
Print (name2)

#-------------------Formatted Output-----------------------
Age=int (Input (' Age: '))
Info= ""
--------Info%s------
name:%s
age:%d
"% (Name2,name2,age)
Print (info)

Info1= ""
--------info1 {_name}------
Name:{_name}
Age:{_age}
". Format (_age=age,_name=name2)
Print (INFO1)

Info2= ""
--------Info2 {0}------
NAME:{0}
Age:{1}
". Format (Name2,age)
Print (Info2)

#------------------Process Control--------------------------
Age1=90
While true: #while循环, true for conditions, appropriate for other conditions, end when conditions are not met
User_input=int (Input (' Please enter: '))
If User_input==age1:
Print (' Well come to.....! ')
Break #结束循环
Elif User_input>age1:
Print (' I am sorry! It is a little bigger! ')
Continue #退出本次循环继续下一次循环
Else
Print (' I am sorry! Some of them is small! ')
Continue
else: #循环的条件不满足执行此处
Print (' Out of limit ')

#---------------------for Loop------------------------
For u in Range (10):
Print (U)

For I in Range (0,10,2): #有条件的打印
Print (i)

Python Basics (ii)

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.