Python data Type--number, string

Source: Internet
Author: User

The Python language is a strongly typed language and is a dynamic language that automatically checks the type of data during run time, so Python does not have to define variable types.

Python variable assignment:

A = 10b = 100c = List or a,b,c = 10,100,list

Python has five standard data types:

    • Numbers (digital)
    • String (String)
    • List (lists)
    • Tuple (tuple)
    • Dictionary (dictionary)

Number (numeric):

Python supports four different numeric types:

    • int (signed integral type)
    • Long (longer integer [can also represent octal and hexadecimal])
    • Float (float type)
    • Complex (plural)

Numeric Type conversions:

int (x) converts x to integer type

STR (x) converts x to string type

Long (x), float (x), complex (x), list (x), tuple (x), Chr (x), UNICHR (), Hex (x), Oct (x) ...

String (String):

There is no character data type in Python, and a single character is a string type

The necessary conditions for equality of two strings are: equal lengths and equal characters at each corresponding position

Attribute: Non-mutable type

Common built-in methods:

String.Join (seq) merges all elements in the SEQ into a new element with Str as a delimiter

String.upper () converts all letters in a string to uppercase

String.Lower () converts all letters in a string to lowercase

String.swapcase () Flips the case of letters in a string

String.find (' str ' [, Beg=0,end=len (String)]) checks if STR exists in string, yes, returns TRUE or 0, otherwise returns false or not 0, "[]" inside the optional, default check entire string

String.index (' str ' [, Beg=0,end=len (String)]) is similar to the String.find command but does not present an error

String.count (' str ', [Beg=0,end=len (String)]) returns the number of STR occurrences in a string

String.Replace (' old ', ' new ' [, NUB]) replaces the old in the string with new, specifying the maximum number of conversions nub, which is the default transform all

String.Split (' str ' [, NUB]) splits a string with str as a string, specifying the number of splits, by default splitting all

Max (String) returns the largest character in Str

Min (String) returns the smallest character in Str

1. Links to Strings

A = ' abc ' b = ' def ' c = a+b or c = ' abc ' def ' #能够自动的将 ' abc ' and ' Def ' are connected together

2. Comparison of strings (CMP)

The CMP method compares two objects and returns an integer based on the result. CMP (x, y) if x< y, the return value is negative if x>y returns a positive value.

A = ' abc ' b = ' ABCD ' cmp (a B)

Python data Type--number, string

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.