Python basic data types and strings

Source: Internet
Author: User

Basic data types


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=16)
Print (v)
-Bit_lenght
# The binary of the current number, represented by at least n bits
R = Age.bit_length ()

String str
S1 = "ASDF"
S2 = "Asdffas"

# test = "ALex"
# First Letter Capitalized
# v = test.capitalize ()
# print (v)

# all lowercase, casefold, a lot of unknown to the corresponding lowercase
# V1 = Test.casefold ()
# print (v1)
# v2 = Test.lower ()
# Print (v2)

# Set the width and center the content
# 20-Finger total length
# * Blank unknown padding, one character, dispensable
# v = test.center (20, "medium")
# print (v)

# Look in the string to find the number of occurrences of the subsequence
# test = "ALEXALEXR"
# v = test.count (' ex ')
# print (v)

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

# owed
# encode
# decode

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

# owed
# test = "12345678\t9"
# v = test.expandtabs (6)
# Print (V,len (v))

# start looking backwards, find the first one, get its unknown
# > 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})

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

Lists List
...
Ganso tuple
...
Dictionary Dict
...

boolean bool
...


Python basic data types and strings

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.