Python Learning Lesson Three

Source: Internet
Author: User

# Python development tool pycharm, software settings in File-setings settings font, style and mouse scrolling zoom out,
# What is a subsequence? A subsequence is a part of a character in a string, such as the Name= "Dongfeng" in a sequence.
# One, digital magic
# 1. int turns a number in a string into an integer, converting the specified string to a specified number of digits
#例:
# num1= "123456"
# V=int (NUM1)
# Print (v)
# c1= "L"
# V=int (c1,35)
# Print (v)
# 2. . Bit_length () calculates the minimum length after the specified number has been converted into 2
# Example:
# v1=255
# v=v1.bit_length ()
# Print (v)
# Two, string magic
# 1. . Capitalize () Capitalize the letter first letter
# zm= "Wei"
# v=zm.capitalize ()
# Print (v)
# 2. . Casefold () turn all letters into lowercase, including other languages. Lower () also turns all letters into lowercase, but only the letters in English are lowercase.
# char1= "WEI"
# v=char1.casefold ()
# Print (v)
# char2= "Lwei"
# v=char2.lower ()
# Print (v)
# 3. . Center () centers the characters and fills them with the specified characters.
# char1= "China"
# V=char1.center ("*")
# Print (v)
# 4. . EndsWith () finds whether to end with the specified character, or False if it is returned; StartsWith () finds whether to start with the specified character, or False if it is true
# c1= "Woshiwodewo"
# V=c1.endswith ("W")
# Print (v)
# c1= "Woshiwodewo"
# v=c1.startswith ("Wo")
# # Print (v)
# 5. . Find () looks for a specified character from within the specified range and cannot find the location found by-1. Do not specify a range to start with 0 bits. Index () Ndex and find, but Index can not find the error, we use. Find () as the main.
# c1= "ASDAFDGHDFGSFD"
# V=c1.find ("D", 3,8) #
# Print (v)#补充: When the specified position is started, the specified character position is counted starting at 0.
# 6. The . Format () format character, replacing the variable in the {} placeholder with the character we specified;. Format_map ({}) replaces the variable in the {} placeholder with the character we specified, behind the map is a dictionary, note that two placeholders are "" and contain curly braces .
# example 1:
# str1= "My Name {name}, this year {age} years old"
# Print (str1)
# V=str1.format (name= "Ali", Age=18)
# Print (v)
# # example 2:
# str1= "My Name {name}, this year {age} years old"
# Print (str1)
# V=str1.format_map ({"Name": "Lilei", "Age":)
# Print (v)
# 7. The . Isalnum () determines if there are any special characters besides letters and numbers, and if there is a return false, no special characters are returned to the True
# v1= "d1a23sd1a3d+0-09"
# v=v1.isalnum ()
# Print (v)

Python Learning Lesson Three

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.