Beginner python: A basic part

Source: Internet
Author: User

some of the content comes from the official website of Liaoche https://www.liaoxuefeng.com/I.. bytes data type

The data that is transferred on the network or on the disk, in bytes.

Details Visible https://www.cnblogs.com/R-bear/p/7744454.html

Ii. list (list) type

increase : 1. Add to specified location: Listname.insert (Index,value)

2. Add to end: Listname.append (value)

Delete: 1. Remove the specified location: listname. Pop (index)

2. Delete End data: Listname.pop ()

Change : Assign value directly to index position: ListName (index) =value;

Check : Use index, index starting from 0, to Len (listname)-1 end, get last element in addition can use Listname[len (listname) 1], can also use listname[-1], Second listname[-2], and so on

Summary: List, is a python built-in sequential collection, can be stored in different data types, the list can be called a two-dimensional (multidimensional) array, when the list is empty, Len () is 0

Third, tuple (tuple) type

Increase: None

Delete: None

Change: None

Check: Tuplename[index]

Summary: Once the initialization is not modifiable, the code is more secure, can be used as a tuple.

Note: When you define a tuple of only one element, you also need to add ', ' after the first element ,

For example: t= (1,) if written in t= (1), where the parentheses are compiled by the compiler into a mathematical operation of the parentheses, it becomes a variable t,t defined value of 1, not a tuple

Iv. Common placeholders

%d integers

%s string

%f floating Point

Example:

>>> ‘Hi, %s, you have $%d.‘ % (‘Michael‘, 1000000)‘Hi, Michael, you have $1000000.‘
如果只有一个占位符,后边的%()中的()可以省略
>>>‘Hi, %s‘%‘bingo‘
' Hi,bingo '

You can use the format () formatting string:
>>> ‘Hello, {0}, 成绩提升了 {1:.1f}%‘.format(‘小明‘, 17.125)‘Hello, 小明, 成绩提升了 17.1%‘
 

Beginner python: A basic part

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.