程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python advanced notes

編輯:Python

Catalog

List is a non numeric data type .

  Iterate through

Tuples (Tuple)

How to define a tuple that contains only one element ?​

Dictionaries

character string

python Built in functions


List is a non numeric data type .

 

list_test = [" A waste of time ", " The secret of success ", " Don't look for someone "]
print(list_test)

index function

effect : Find the subscript of a data .

list_test = [" A waste of time ", " The secret of success ", " Don't look for someone "]
print(list_test.index(" A waste of time "))

del keyword

effect : Delete a variable from memory .

ff = "ff"
del ff
print(ff)

  Iterate through

list_test = [" Don't waste time ", " The secret of success ", " Don't look for someone "]
for my in list_test:
print(" remember %s" % my)
# Iterate through

Tuples (Tuple)

Tuples are similar to lists , The difference is that the elements of a tuple cannot be modified .

Tuples : A sequence of elements .

Used to store a string of information , Between data “,” Separate .

Tuple use () To define . 

How to define a tuple that contains only one element ?

  When defining a tuple that contains only one element like this ,python The interpreter will automatically ignore the parentheses . You need to use commas to separate .

single_tuple = (5,)
print(type(single_tuple))

Tuple correlation function :

index() and count().

Tuple traversal can also be done iteratively .

If you want to modify the tuple, you can use list Function to list , It can be modified .

If you don't want the list to be modified , You can go through tuple Function to tuple .

Dictionaries

Dictionary use {} Definition . It uses key value pairs to store data , Key value pairs are separated by commas .

key Key It's the index .

value value Is the data .

Keys and values are preceded by : Separate .

Keys are unique , Cannot have more than one key with the same name .

Values can be of any data type , But keys can only use strings , A number or tuple .

The difference between a dictionary and a list : A list is an ordered collection of objects , A dictionary is an unordered collection of objects .

It is usually used to store information about an object .

xiaoming_inf = {"name": " kitten ", "age": 17}
print(xiaoming_inf["name"])

character string

python You can use either double quotation marks or single quotation marks to define .

Many methods are defined in the string , The subscript is found , have access to find function , This function is related to index Difference of function :find() If a non-existent value is found, it will be returned directly -1 No errors are reported ,index Will report an error directly .

The methods in the string are mainly about judging white space characters , Judge whether it is a number , Find and replace , Case write , Alignment mode .

python Built in functions

 


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved