Python Road, Day2-python Foundation, list, loop

Source: Internet
Author: User

1. List Exercises
NAME0 = ' Wuchao '
name1 = ' jinxin '
name2 = ' Xiaohu '
name3 = ' Sanpang '
name4 = ' Ligang '

names = "Wuchao jinxin xiaohu sanpang Ligang"
a=[' Wuchao ', ' jinxin ', ' Xiaohu ', ' Sanpang ', ' Ligang ']

#增删改查
#增 slices
print (a[1:]) #取到最后
print (a[1:-1]) #取到倒数第二值
print (a[1:-1:1]) #从左到右一个一个取 "1" is the step size
print (a[3::-2]) #从左到右隔一个取一个


names = [' Alex ', ' Tenglan ', ' Eric ', ' Rain ', ' Amy ']
# a=[' Alex ', ' Tenglan ', ' Eric ', ' Rain ', ' Amy '
print (Names[1:4])
print (names[1:-1])
print (Names[0:3])
print (Names[:3])
print (names[3:])
print (names[3:-1])
print (Names[0::2])
print (Names[0::2])
name = "\n\t Alex li;rain Wang; Jack \ t "
print (name)
print (Name.strip ()) #脱掉, strip girl

Print (Name.split (";")) #分割, divide a character into a list by a space
print (len (name)) #长度

2, increase and revise the search
names = ["Su Haozhi", "Chin", "Li Zhi", "Inflammation Dragon", "full", "liar", "Li Zhi"]
print (names)
print (names[-1])
Print (names.index ("Li Zhi")) #返回元素的索引 \ Subscript
print (Names[3:5]) #0 1 2 3 4 5 6, index 3 to 5 of the previous
Print (names.count ("Li Zhi")) #统计数量
#print (type (names))
names.append ("bald") #默认追加到最后一个
print (names)
#insert插入
Names.insert (4, "Chen Tao") #在索引4饱满之前加一个陈涛
Names.insert (3, "Hongzhiqiang") #在索引3炎龙之前加一个洪智强
print (names)
Print (Names.pop (4)) #删除, delete the last one by default
names.remove ("Li Zhi")
del names[1] #删除
print (names)
3. Notes and Assignments
#!/usr/bin/env python
#_ *_coding:utf-8_*_
__author__ = ' Yu '
Today topic
character encoding
Data Type
Str


Number Type
int integral type
Long Integer type
float
Negative number

BOOL Boolean
true True
false False
character
string Common functions:
Remove whitespace
Split
length
Index
slices

List
Dict
Set

For : else


While : Else


8 4 2 1
1 1 1 1 1 1 1 1 1 1

1024Bytes = 1KB = 1KB
1024KB = 1MD = 1 million bytes = 1 MB
1024MB = 1GB = HD short, 1080P 20 min
1024GB = 1TB
1024TB = 1PB



a binary is the smallest representation unit in a computer.
1 Bytes is the smallest storage unit in a computer

ASCII 256, 8 bits per character
GB2312 1980 67xx
GBK1.0 1995 21000
GB18030 27000

Unicode Universal Code
utf-32 = 4 bytes
utf-16 = 2 bytes

single and double quotes do not have any difference, only for single-line
three-quote single or double quotation marks for multi-line strings, or multiline comments





Job 1
Jump out of the multilayer loop, three-layer cycle, the innermost layer, jumping out of 3 layers,
Job 2
Shopping Cart Program (knowledge points, loops, lists,
)

python shopping.py

Input your salary:5000
you can buy the following things:
1.iphone 5800
2.coffee
3.book
4.condom
>>: 1
can't afford to print, how much is the difference?
>>:2
can afford to put into the shopping cart, deduct money, while printing the balance ... 4970
>>:3
...
>>:4

>>:q
you bought the following things,
Coffee
Book ...
How much money do you have?
Bye


Python Road, Day2-python Foundation, list, loop

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.