Professional Documents
Culture Documents
Python Refresher Course: By:A.Shobharani
Python Refresher Course: By:A.Shobharani
By:A.Shobharani
Shobha
Python - Numbers
Number data types store numeric values. They are
immutable data types, which means that changing the value
of a number data type results in a newly allocated object.
Number objects are created when you assign a value to
them. For example:
var1 = 1
var2 = 10
You can also delete the reference to a number object by
using the del statement. The syntax of the del statement is:
del var1[,var2[,var3[....,varN]]]]
You can delete a single object or multiple objects by using
the del statement. For example:
del var del var_a, var_b
Python - Numbers
Python supports four different numerical types:
int (signed integers): often called just integers or ints, are positive or
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
Constant Description
pi The mathematical constant pi.
e The mathematical constant e.
Numbers are
immutable
x 4.5
>>> x = 4.5
>>> y = x y
>>> y += 3
x 4.5
>>> x
4.5 7.5
>>> y y
7.5
shobha 9
Strings
• String is a sequence of characters.
• String may contain alphabets, numbers
and special characters.
• Usually strings are enclosed within a
single quotes and double quotes.
• Strings is immutable in nature.
• Example:
a=„hello world‟
b=“Python”
Problem Solving and Python Programming 10
Accessing Values in Strings:
Python does not support a character type; these are treated as
strings of length one, thus also considered a substring.
To access substrings, use the square brackets for slicing along with
the index or indices to obtain your substring:
Example:
var 1 = 'Hello World!'
var2 = "Python Programming"
print "var1[0]: ", var1[0]
print "var2[1:5]: ", var2[1:5]
print(c)
Problem Solving and Python Programming 19
Operators on String
• The Concatenate strings with the “*”
operator can create multiple concatenated
copies.
• Example:
>>> print("Python"*10)
PythonPythonPythonPythonPythonPython
PythonPythonPythonPython
str2="black"
print("Is both Equal:",
str1==str2) print("Is str1> str2:",
str1>str2) print("Is str1< str2:", OUTPUT:
rstrip() strip()
Output:
Output: