Professional Documents
Culture Documents
Tour
Mrs. MADHUMITA RANI
P.G.T (Computer Science )
J.N.V. Bangalore Urban
Introduction
• We know that data types are nothing but the type of data we use to the
variable, method etc.
• We have following data types in Python.
1. Number
2. String
3. Boolean
4. List
5. Tuple
6. Set
7. Dictionary
Number
In Python we use number data type to store numeric value.
• Integer – Whole number without fraction parts ex: 1, 2 etc. Use 32 bits to
store value.
• Long integer – It store larger integer number. Use 32 bits to store value.
• Floating Point – It is a positive or negative real numbers with a
decimal point.
• Complex – Complex numbers are combination of a real and imaginary part.
Complex numbers are in the form of X+Yj, where X is a real part and Y
is imaginary part.
Input : a = complex(5) Output : (5+0j)
print(a)
String
• A string is a sequence of characters. In python we can create
string using single (' ') or double quotes (" ").Both are same in
python.
Ex : - Input :
str='computer science’
print('str-', str) # print string
Output :
str- computer science
String Method
Method Description
Capitalize() Returns a copy of string with its first character as capita
Find() Returns the lowest index in the string
Isalnum() Returns true if the character in the string are alphanumeric
Isalpha() Returns true if the character in the string are alphabetic
Isdigit() Returns true if the character in the string are digit
Islower() Returns true if all the cased characters in the string are lowercase
Isupper() Returns true if all the cased characters in the string are uppercase
Title() Returns True if the string is in title case
Swapcase() Returns a copy of the string with uppercase character converted to lowercase and
vice versa
Partition() Splits the string at the first occurrence of argument
String Methods contd..
Method Description
Isspace() Returns true if there are only whitespace character in the string
Count() Returns the number of non-overlapping occurrence of substring in the given string
lstrip Returns a copy of the string with leading characters removed
rstrip Returns a copy of the string with trailing characters removed
Startswith() Returns true if string starts with the argument otherwise return false
Endswith() Returns true if string ends with the argument otherwise return false
• Dictionary • String
• List • Integer
• Tuples
• Booleans
• Floating Point
Arithmetic Operators
Operators are special symbols in Python that carry out arithmetic or logical
computation. The value that the operator operates on is called the operand.
Arithmetic operators Used for mathematical operation
Operator Meaning Example
+ Add two operands x + y +2
- Subtract right operand from the left x - y -2
* Multiply two operands x*y
/ Divide left operand by the right one x/y
% Modulus - remainder of the division x%y
// Floor division - division that results into whole number x // y
** Exponent - left operand raised to the power of right x**y
Comparison operators - Used to compare values
Input Output
x=1 Matched
y=2
if(x==1 and y==2):
print(‘Matched')
if-else Statements
• If-else statement executes some code if the test expression is
true
and some other code if the test expression is false.
Input Output
a=10 less than 100
if(a < 100):
print(‘less than 100')
else:
print(‘more than
equal 100')
Nested if-else statement
The nested if...else statement allows you to check for multiple
test expressions and execute different codes for more than two
conditions.
Input Output
Input Output
for letter in ‘rajeev': r
if letter == 'e' or letter == ‘a': J
continue v
print( letter)
Input Output
for letter in 'rajeev': Current Letter : a
if letter == 'a' or letter == 'j':
break
print('Current Letter :', letter)
Pass Statement: We use pass statement to write empty loops. Pass is also used for empty control
statements, function and classes.
for letter in 'rajeev': Last Letter : v
pass
print('Last Letter :', letter)