You are on page 1of 16

Week 1

Lecture 1.2

Starting with Print Statement :-


ADDITIONAL INFORMATION :-

1. Backslash n (\n) is the character that is used to create the new line.

2. You can comment in python using a single hash (#) symbol at the beginning.

3. Comments are programmer-readable explanations and generally ignored by


compilers and interpreters.

Lecture 1.3

More about Print Statement :-


Common syntax errors that needs to be taken care of :-

1. Spellings of print in print statements should be correct.


2. You must use the round brackets after print.
3. You can use single or double quotes in a print statement.
4. Do not use the combination of quotes viz. ----> print( ' hello " ) <---- if you have
started with a single quote then end with a single quote.

Lecture 1.4

Variables :-
Input Statement (Let’s interact with the end user) :-

Lecture 1.5
Variables and Input Statements :-

Lecture 1.6

Merging Print and Input Statements :-

In code 2,
' r ' and ' area ' are variables.
The value of pi that is always 3.14 is the Literal.

Lecture 1.7

Let's learn about data types :-

The command —> type(variable)<— prints the data type of the value that is stored in
the variable.

Data type 'int' means integer.


Data type ‘float’ is used for decimal type numbers.
Data type ‘str’ is for strings, a string is a value representing text.
Learning about Lists :-

Additional info :-
Computers start counting from the number zero!
Lecture 1.8

Boolean Data type :-

Conversion of one data type to another (Type conversion


or Type casting) :-

The variable 'a' printed the value as 4 and not 4.5 , This is because we asked the
variable to store only integer values in it. So, it ignored the decimal part and stored the
integer part.
Similarly you can convert integer and float to string, give it a try!

The variable f is false because when computers convert integers into boolean every integer
except 0 is considered as true, 0 is the only value which gives a boolean value as false.
Here, the variable k is true because the zero in variable k is neither integer nor float. It is
a string and string representation of boolean is always true except one condition: if the
string is empty the boolean representation of empty string will be false.

Lecture 1.9

Operators and Expressions :-


Lecture 1.10

More about Operators :-

In python there are 3 types of operators :-

1. Arithmetic Operators
2. Relational Operators
3. Logical Operators

Floor division operator will only give the integer part as the output and leave the decimal part.
Division operator gives the integer as well as the decimal part as the output.
Output of Relational operators will always be a boolean value.
Lecture 1.11

More about Strings :-

Indexing, Slicing and more :-

In command —>print(s[1:5]) <— It prints the letter from 1st to the 4th position, the output will be
offe , it goes from 1 to 5-1 which is 4. (String slicing)
In part 2 we stored string type value in variables k and p. Hence, variable n
concatenates both the strings and gives output as 38. Addition operator between strings
means concatenation!

Lecture 1.12

Some concepts about strings :-


When we use comparison operators with strings it works differently, it will compare the string
character by character.
Here, the first letter of 'apple' is 'a' which is being compared with the first letter 'o' of the word
'one' , As 'a' comes before ‘o’ , so it can not be greater than the letter 'o'. Hence, it gives the
output as False.

In —>print('abcdef' < 'abcde') <— Letter 'f' on the left side has no letter left on the right side to
be compared with. Therefore, 'f' can not be smaller than nothing. Hence, It is false.

You might also like