Python base day02 basic data type

Source: Internet
Author: User

Number (digital)--->int, float, complex (plural)

In Python3, shaping (int) is a common integer: 1,100,500,1000 ...

Floating-point (float) is our common decimal notation, such as 0.5, 1.2, 3.14, and so on.

Complex numbers (complex, complex numbers are made up of real and imaginary parts, and can be represented by a + BJ, or complex (a, b), where both real and imaginary parts of a complex number are floating-point types.

Property Describe
Num.real The real part of the complex number
Num.imag The imaginary part of the complex number
Num.conjugat ()

Returns the conjugate arithmetic of the complex number

n = ' 123 ' Print (type (n)) m = Int (n) print (type (m)) num = ' 101 ' a = Int (num, base=2) b = int (num, base=8) c = int (num, base=10) 
   # equals int (num) d = int (num, base=16) print (a) print (b) print (c)

Execution Result:

<class ' str ' ><class ' int ' >565101257

  

String (string)--->str

The strings in Python are enclosed in single quotation marks (') or double quotation marks ("), while the backslash (\) is used to escape the special characters, the plus sign (+) is the connector for the string, and the asterisk (*) indicates that the current string is copied, followed by the number of copies.

The value received by input defaults to the STR type, and a type () can be used to return a data type.

s = ' lcgsmile ' S1 = s.capitalize ()  # first letter capitalized. Print (S1) s2 = S.casefold ()  # string full output is lowercase compared to lower () to recognize more than ASCII (A-Z) characters. Print (s2) s3 = S.center (A, '-')   # The original string is centered, filled with a new string of a certain length, and the default padding character is a space. Print (s3) S4 = S.endswith (' e ')  # Determines whether the string ends with the specified suffix, if the end of the specified suffix returns trueprint (s4) S5 = S.find (' C ')  # finds the substring at the beginning of the string. Print (s5) s6 = S.index (' g ')  # throws an exception if the containing substring returns the starting index value. Print (S6)

  

Execution Result:

Lcgsmilelcgsmile------lcgsmile------True12

List (listing)--->list

Tuple (tuple)--->tuple

Dictionary (dictionary)--->dict

Python base day02 basic 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.