0% found this document useful (0 votes)
56 views2 pages

Topic Covered

The document covers the following topics in a Python class: 1) Data types in Python including integer, float, string, complex number, and boolean. It provides examples and descriptions of each. 2) Comments in Python code and how they are used to explain code. 3) Input and output functions, specifically how input() gets user input as a string and print() displays output.
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)
56 views2 pages

Topic Covered

The document covers the following topics in a Python class: 1) Data types in Python including integer, float, string, complex number, and boolean. It provides examples and descriptions of each. 2) Comments in Python code and how they are used to explain code. 3) Input and output functions, specifically how input() gets user input as a string and print() displays output.
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/ 2

Class 2 (02-05-2020): -

Topic Covered:
Data Type: - Integer, Float, String, Complex Number, Boolean
Comments in Python and Input &Output Functions.

Data Types:
1. Integer:
 They are positive or negative whole numbers with no decimal
point.
 Range: Unlimited Range, we can any integer whether small or
long.
 Function: int( )
 Example: a = 15
2. Float:
 They 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).
 Range: Maximum = 1.8e+308
Minimum = 1.0e-324
 Function: float( )
 Example: a = 15.16
3. String:
 Python string is a collection of Unicode characters.
 Python strings can be enclosed in single, double or triple quotes.
Eg: 'BlindSpot', "BlindSpot", ' ' 'BlindSpot' ' ', """Blindspot"""
 String elements can be accessed using an index value, starting
with 0.
Eg:
msg = 'Hello'
0 1 2 3 4
‘H’ ‘e’ ‘l’ ‘l’ ‘0’
-5 -4 -3 -2 -1
a = msg[ 0 ] # yields H
b = msg[ 4 ] # yields o
d = msg[ -1 ] # yields o
e = msg[ -2 ] # yields l
f = msg[ -5 ] # yields H
 Slicing of String: s[start : end+1 : step]
 A sub-string can be sliced out of a string.
 s[ start : end + 1 ] - extract from start to end
 s[ start : ] - extract from start to end
 s [ : end + 1] - extract from start to end
 To Convert negative index to positive index:
Negative index + Length of String = Positive index
 Examples of Valid String Literals:
“abcd”, “1234”, “%$#%”, “???#”, “Ram1234”
 To find length of string we use len( ) function:
a = “Hello”
then, len(a) = 5

4. Booleans: These represents the truth values False or True.


O ( ZERO) Represent False
All Values excluding O ( ZERO) Represent True (Eg:1,-9,52).
5. Complex Numbers: Python represent complex number in the form of
A + Bj.
Eg: z = 5+2j
z.real gives real part in complex number.
z.imag gives the imaginary part.
Comments in Python:
 Comments can be used to explain Python code.
 Comments can be used to make the code more readable.
 Comments starts with a #, and Python will ignore them.
Example:
#This is a comment
print("Hello, World!")

Input and output in Python:


- input() function is use to input data entered by user and return in
form of string type.
- print() function is use to print the data on screen.

You might also like