Day1 2
Day1 2
• Numbers
• String
• List
• Tuple
• Dictionary
• set
Working With Numbers
• The interpreter acts as a simple calculator: you can
type an expression at it and it will write the value.
• Expression syntax is straightforward:
• operators +, -, * and / work just like in most other
languages (for example, C);
• parentheses can be used for grouping.
Examples
• float (floating point real values) :represent real numbers and are
written with a decimal point dividing the integer and fractional parts.
• Floats may also be in scientific notation, with E or e indicating the
power of 10 (2.5e2 = 2.5 x 102 = 250).
a+bj
0+1j
Working With Numbers
• Complex numbers are also supported;
• imaginary numbers are written with a suffix of j or J.
• Complex numbers with a nonzero real component are written
as (real+imagj), or can be created with the complex(real,
imag) function.
Working With Numbers
• Complex numbers are always represented as two floating
point numbers, the real and imaginary part.
• To extract these parts from a complex number z, use z.real
and z.imag.
Working With Numbers
• The conversion functions to floating point and integer (float(),
int() and long()) don’t work for complex numbers — there is
no one correct way to convert a complex number to a real
number.
• Use abs(z) to get its magnitude (as a float) or z.real to get its
real part.
Mathematical Functions
Example
Mathematical Functions
x is a numeric expression.
Example
Mathematical Functions
Example
Mathematical Functions
0 1 2 3 4 5 6 7 8 9
CDAC Noida
-2 -1
s=“CDAC Noida
s[5] N