int float complex Variables of numeric types are created when you assign a value to them: Example x = 1 # int y = 2.8 # float z = 1j # complex print(type(x)) print(type(y)) print(type(z)) To verify the type of any object in Python, use the type() function: Int:- Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length. Example Integers: x=1 y = 35656222554887711 z = -3255522 Float:- Float, or "floating point number" is a number, positive or negative, containing one or more decimals. Example- Floats: x = 1.10 y = 1.0 z = -35.59 i = 35e3 j = 12E4 k = -87.7e100 Float can also be scientific numbers with an "e" to indicate the power of 10. Complex:- Complex numbers are written with a "j" as the imaginary part: Example Complex: x = 3+5j y = 5j z = -5j TYPE CONVERSION You can convert from one type to another with the int(), float(), and complex() methods: Example Convert from one type to another: x = 1 # int y = 2.8 # float z = 1j # complex #convert from int to float: a = float(x) #convert from float to int: b = int(y) #convert from int to complex: c = complex(x) print(a) print(b) print(c) print(type(a)) print(type(b)) print(type(c)) Note: You cannot convert complex numbers into another number type. STRING LITERALS String literals in python are surrounded by either single quotation marks, or double quotation marks. 'hello' is the same as "hello". You can display a string literal with the print() function: Example print("Hello") print('Hello') ASSIGN STRING TO A VARIABLE Assigning a string to a variable is done with the variable name followed by an equal sign and the string: Example a = "Hello" print(a) MULTILINE STRINGS You can assign a multiline string to a variable by using three quotes: Example You can use three double quotes: a = """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.""" print(a) Or three single quotes: Note: in the result, the line breaks are inserted at the same position as in the code. PYTHON CONSTANTS Sometimes, you may want to store values in variables. But you don’t want to change these values throughout the execution of the program. To do it in other programming languages, you can use constants. The constants like variables but their values don’t change during the program executes. The bad news is that Python doesn’t support constants. To work around this, you use all capital letters to name a variable to indicate that the variable should be treated as a constant. For example: MY_PHONE_NUMBER = 9100000000 When encountering variables like these, you should not change their values. These variables are constant by convention, not by rules. THANK YOU
(Ebook) Algebraic Number Theory for Beginners: Following a Path From Euclid to Noether by Stillwell, John ISBN 9781316518953, 9781009004138, 9781009001922, 1316518957, 1009001922, 1009004131 all chapter instant download
(Ebook) Algebraic Number Theory for Beginners: Following a Path From Euclid to Noether by Stillwell, John ISBN 9781316518953, 9781009004138, 9781009001922, 1316518957, 1009001922, 1009004131 all chapter instant download