COURSE SECTION 01 OF 06

Introduction to Python and Operators

Lesson material assembled from the files you supplied.

Course notes

Content below is transcribed from the supplied course document. The original wording and terminology are retained.

Introduction to Python

Statement

print(‘t’)

o/p = ‘t’

Expression

i.e. 5+5= 10 is a value, if i > 1

Variable

x = 4.01 is store of variables or x[1] = x[2] is a reference

Reserve Words or Keywords in Python

def, len, lambda, False, True, in, range, list, None, del, import, return

Python Standard Type Hierarchy:

None

Ellipses

Numbers – int, float & complex no.

Sequences – immutable & mutable

Mappings

Callable types – user-defined functions, user-defined methods, built-in functions & built-in methods

Modules – import

Files – world.py file

Internal Types

Three Important Properties associate with every objects.

Identity = L = name of variable

Type

Value is ‘1’

L = [‘1’]

Variable

No keywords

Letter, numbers, underscore

Length_of_wire_1

Python is case sensitive, hence variable is case sensitive

LENGTH_OF_WIRE_1 is not equal to Length_of_wire_1

1_w is not vriable

= assignment operator

Operators

Arithmetic

Power - ** 2**2 = 4

Mutiple - * 2*2 = 4

Divison - / 2/2 = 1

Modulus - % 2%2= 0

Addition - + 2+2 = 4

Subtraction - - 2-2= 0

Floor Division - //

10//3 = 3.0

10.78//3 = 3.0

11.78 // 3 = 3.0

Comparison

3 == 4 is False

==,<,>,<=,>=,!=

Assignment is =

Bitwise

| is OR operation, & is AND operation, ~ is Binary one Complement,

^ is XOR operation, << is binary left shift operator, >> is binary right shift operator

242 =1 1 1 1 1 0 0 1 0 is binary form of 242

|

12 = 0 0 0 0 1 1 0 0

254 = 1 1 1 1 1 1 1 0

242 | 12 = 254

Logical

Membership - in and not in

‘w’ in [‘w’, ‘o’, ‘t’] is True

‘o’ not in [‘w’, ‘o’, ‘t’] is False

Identity

V = ‘b’

Type Conversions – value that an operate acts on.

a = 10

type(a) is ‘int’ class

b = str(a)

‘10’

type(b) is ‘str’ class

int(b) or int(str(a))

b. a -- 10. type(a) is ‘int’ class

10

type(b) is ‘int’ class

Text Type: | str

Numeric Types: | int, float, complex

Sequence Types: | list, tuple, string

Mapping Type: | dict

Set Types: | set, frozenset

Boolean Type: | bool()

Binary Types: Dictionary DT | T r u e, F a l s e Dict = {‘key’ : ‘value’}

None Type: | NoneType

🐍 Try Python Yourself

Practise Python programming directly in your browser. Write your code below and click Run Python.

Python environment is not loaded yet.

Output

Loading Python environment...

Download the supplied Python examples

Topics identified in the course materials

Next section →

← Back to course curriculum