One of the basics of Python

Source: Internet
Author: User

In order to get a better understanding of the Python language, I find it very necessary to take notes.

First, based on the current trends in Python, all of the notes I've made are Python3 and above.

The following is a formal introduction to Python.

1. Computer languages generally have input and output, and Python is no exception:

Output function: print ()

Input function: input ("You can add a hint here")

2. Notes

Line comment: Add # at the beginning

Multiline Comment: Start and end with "" "or" "

3. Data type

Number (numeric):

Int:num1=12

float:num2=12.0

Complex:num3=1+2j

Str (String):

str= ' Hello World '

Print (Str[0:2])--"he #在python里面可以任意切割字符串, [0:2] means starting from 0 bits to 2nd bit but not including

Print (str[0:2]*2)--"hehe #*2 printing two times Str[0:2]

str[1]= ' t ' #报错, in Python str is not allowed to change

List (lists):

list=[' Hello ', +, ' Ben ']

list1=[' world ',%, ' Han '

Print (list[2])--"Ben

Print (List[0:2])--"[' Hello ', 21]

Print (List+list1)-"[' Hello ', ' + ', ' Ben ', ' World ', ', ' Han ']

List[1]=18;print (List[1])--"#在Python中同一行写多个语句在中间加上;

Tuple (tuple):

Tuple= (' book ', ' Next ', 17)

#与列表相似, the difference is that a tuple cannot modify

#当tuple只有宇哥元素是后面需要加上, e.g. t= (12,)

Set (SET):

set={"Yellow", "blue", "green"} #set是一个无序且不重复的序列

Dictionary (dictionary):

dic={"name": "Rose", "age": +, "Sex": "Girl"}

dic[' age ']=16 #字典通过key修改value

Dic.values () #获取所有的values

Dic.key () #获取所有的key

#创建空字典是用 {}, empty collection with ()

OK, this article is here, I hope to help you:)

      

      

      

    

      

      

      

One of the basics of Python

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.