0% found this document useful (0 votes)
3 views13 pages

class 7 python

Uploaded by

shivangiupa123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
3 views13 pages

class 7 python

Uploaded by

shivangiupa123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 13

PYTHON

LECTURE-7
Presented by Computer G
PYTHON NUMBERS

There are three numeric types in Python:


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

You might also like