Python data type

Source: Internet
Author: User

logical operators for Python
Number operators: +- / %
Relational operators: A==b, A>b, A<b, a!=b
Assignment operator: a=b (assigns the value of B to a), + =, a+=b,-=,
=,/=
Logical operators: And, or, not, (if A==b and a!=10:)

1, int integer

a=10print(a)

2, Boolean bool is divided into two kinds, one is True, one is False

>=1 True<=0 False

3. Float Float value

a=3.141592653m = round(a,2) # 保留两位小数print(m)

Round (Float,ndigits)
Float stands for numbers, ndigits represents precision
The big rule is rounding

4, the string str ' abc ' "ABC" "' ABC '

string = ‘abcadefgahiagh‘print(string)

5, find find string, if found on the return string to start the subscript, if not found return-1

print(string[0]) # 打印下标为0的值print(string[3]) # 打印下标为3的值print(string[:]) # 打印所有值result = string.find(‘def‘)print(result)# 3 返回下标3

6. Replace replacement

print(string.replace("a","AAA"))

7. Split Separator

# join(可迭代对象) 一般为list字符串newlist = string.strip().split("a")print(newlist)print(" ### ".strip().join(newlist))

8, strip () remove the null character before and after the string

string.strip()print("My string is : %s" % string)print("My string is : {0}".format(string)) # 推荐使用,效率最高print("hello" + "world")

9. The list is made up of elements that are arranged in a series of specific order,
You can add any object, such as a string, a number, a dictionary, to a list,
There is no relationship between the elements, and the list is self-labeled, starting from 0 by default

l = [1,2,3.1415926,‘a‘,‘b‘,‘c‘,True,{"name":"zyy"}]print(l)# [1, 2, 3.1415926, ‘a‘, ‘b‘, ‘c‘, True, {‘name‘: ‘zyy‘}]

10. What are the common methods of dictionaries?

l.append("hello")print(l)# [1, 2, 3.1415926, ‘a‘, ‘b‘, ‘c‘, True, {‘name‘: ‘zyy‘}, ‘hello‘]

11, Pop delete element, the last element is deleted by default

l.pop()print(l)# [1, 2, 3.1415926, ‘a‘, ‘b‘, ‘c‘, True, {‘name‘: ‘zyy‘}]l.pop(2) # 删除下标为2的元素print(l)# [1, 2, ‘a‘, ‘b‘, ‘c‘, True, {‘name‘: ‘zyy‘}]

12, remove delete element, delete element directly, remove (value)

# index(value) 查找元素对应的下标print(l.index("a"))# 2m = [1,34,234,54,543,5,533,4,5432]print(m)# [1, 34, 234, 54, 543, 5, 533, 4, 5432]m.sort()     #print(m)# [1, 4, 5, 34, 54, 234, 533, 543, 5432]m.reverse()print(m)# [5432, 543, 533, 234, 54, 34, 5, 4, 1]

13. Insert inserts a new element, insert (index, value)

m.insert(3,"hello")print(m)

Python data type

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.