[go: up one dir, main page]

0% found this document useful (0 votes)
2 views18 pages

Day1 2

python notes

Uploaded by

dasaf81046
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views18 pages

Day1 2

python notes

Uploaded by

dasaf81046
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Python Programming - II

-By Nimesh Kumar Dagur, CDAC,


India
Standard Data Types:

• The data stored in memory can be of many types.


• For example, a person's age is stored as a numeric value and
his or her address is stored as alphanumeric characters.
• Python has various standard types that are used to define the
operations possible on them and the storage method for each
of them.
Standard Data Types:

Python has following standard data types:

• 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

In Python 3.x version


Python Numbers
Python supports following different numerical types
• int (signed integers): positive or negative whole numbers with no
decimal point.

• long (long integers ): integers of unlimited size, written like integers


and followed by an uppercase or lowercase L. It is not supported in
Python 3.x version.

• 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).

• complex (complex numbers) : are of the form a + bJ, where a and b


are floats and J (or j) represents the square root of -1 (which is an
imaginary number).
• The real part of the number is a, and the imaginary part is b.
Working With Numbers
• The equal sign (’=’) is used to assign a value to a
variable. Afterwards, no result is displayed before
the next interactive prompt:
Working With Numbers
• A value can be assigned to several variables
simultaneously:
Working With Numbers
Variables must be “defined” (assigned a value)
before they can be used, or an error will occur:
Working With Numbers
• There is full support for floating point; operators
with mixed type operands convert the integer
operand to floating point:

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

• abs() : The method abs() returns absolute value of x - the


(positive) distance between x and zero.
Syntax

Example
Mathematical Functions

• ceil() : The method ceil() returns ceiling value of x - the


smallest integer not less than x.
Syntax

x is a numeric expression.

Example
Mathematical Functions

• floor() : The method floor() returns floor of x - the largest integer


not greater than x.

Example
Mathematical Functions
0 1 2 3 4 5 6 7 8 9

CDAC Noida
-2 -1

s=“CDAC Noida

s[5] N

You might also like