Python old boy Day10

Source: Internet
Author: User

1. Operators
The result is a value
Arithmetic operations
A = 10 * 10
Assignment operations
A = a + 1 a+=1

The result is a Boolean value
Comparison operation
A = 1 > 5
Logical operations
A = 1>6 or 1==1
Member operations
A = "mosquito" in "Zheng Jianwen"

2. Basic data type

Python2 Int and long

only int in Python3.

numeric int, all functions, all in int
A1 = 123
A1 = 456

-INT
Convert a string to a number
A = "123"
Print (Type (a), a)

b = Int (a)
Print (type (b), B)

num = "0011"
v = int (num, base=2) equals num as a binary output in decimal
Print (v)


-Bit_lenght
Binary of the current number, represented by at least n bits
R = Age.bit_length ()

Age = 5
# 1 1
# 2 10
# 3 11
# 4 100
# 5 101

Print (R)

#首字母大写

Test = "ALex"
v = test.capitalize ()
Print (v)

#所有变小写, Casefold, a lot of unknown to the corresponding change lowercase
V1 = Test.casefold ()
Print (v1)
V2 = Test.lower ()
Print (v2)

#设置宽度, and center the content
Total length of 20-generation finger
Blank unknown padding, one character, optional
v = test.center (20, "medium")
Print (v)

#去字符串中寻找 to find the number of occurrences of a subsequence
Test = "ALEXALEXR"
v = test.count (' ex ')
Print (v)

Test = "ALEXALEXR"
v = test.count (' ex ', 5,6)

5,6 represents the start and end coordinates of a string
Print (v)

# What's the end of what?
# Start with what?
Test = "Alex"
v = test.endswith (' ex ')
v = test.startswith (' ex ')
Print (v)

#从开始往后找, after finding the first one, get its position
> or >=
Test = "Alexalex"
# Not found-1
v = test.find (' ex ')
Print (v)

# Index not found, error ignored
Test = "Alexalex"
v = test.index (' 8 ')
Print (v)


# formatting, replacing placeholders in a string with the specified values
Test = ' I am {name} ', age {A} '
Print (test)
v = test.format (name= ' Alex ', a=19)
Print (v)

Test = ' I am {0}, age {1} '
Print (test)
v = Test.format (' Alex ', 19)
Print (v)

# formatted, incoming value {"Name": ' Alex ', ' a ': 19}
Test = ' I am {name} ', age {A} '
V1 = Test.format (name= ' DF ', a=10)
V2 = Test.format_map ({"Name": ' Alex ', "a": 19})

The last two sentences have the same effect.

# whether the string contains only letters and numbers
Test = "123"
v = test.isalnum ()
Print (v)

Python old boy Day10

Related Article

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.