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