Python Lecture1
Python Lecture1
Programming Languages:
INPUT- The instructions provided to the computer by users like us in order to perform a task.
PROCESS- The computer reads and understands our instructions in order to perform our task.
OUTPUT- The result of the computer’s process based on the instructions provided by us.
Instructions- The instructions that are provided must be in a proper specified format and there
can’t be any changes in the format. These instructions altogether are called the program or the
code.
Errors/Mistakes- These are encountered by the computer when the instructions provided by
the users don’t make sense to it. This mostly happens when we don’t provide instructions in the
proper format or due to some basic grammatical/ human errors from the user’s side.
Various types of Programming Languages- Just like we speak in English, Hindi or Marathi i.e
we have multiple ways of communicating with people. The choice of a language is purely based
on one’s comfort/dialect/mother tongue. Similarly, we have the choice of providing instructions to
the computer in any language of our choice. But in this case, these languages are known as
Programming Languages.
What is Python?
It is a programming language, and is also considered to be one of the easiest amongst others.
Instructions/ programs/ codes can be written in Python to get a job done. The computer
processes this code and returns an output.
Features Of Python:
From the above mentioned structure, we will learn about the first two steps:
Variables:
Variables are nothing but a storage space which we have created in order to store some values/
facts or an input taken from the user. This storage space is created inside the computer
memory. Each variable can store only one value at a time. If a new value is written again, then
the previous value is deleted and the new one is stored.
While writing variables we use the assignment operator(=), which is nothing but the equals-to
symbol. Examples are as follows:
In the above statements, a, b, c, d are variables/ variable names and 10, 4, 10-4, 45-b are the
values. These values are stored/ assigned to the variable. For eg, the value 10 is stored inside
a, the value 10-4 is stored inside c.
There are some instructions required to write variable names(refer book page no. 94)
Data Types:
A data type in simple words is the type of information/ value which we’ll be storing inside a
variable. There are different data types such as:
1. Integer: They are nothing but numeric values that consist of digits and numbers. The only
restriction here is that it has to be a whole number i.e a number without decimals. Eg: a=10 is
an integer data type but a=10.75 is not accepted as integer. There are three types of integers.In
order to specify a variable as integer type, we write ‘int’ in the program
2. Float: They are numeric values which can contain fractions as well as normal integers.
Numbers with decimals can also be stored inside variables for float data type. In order to specify
a variable as float type, we write ‘float’ in the program.
3. String: This data type is used to specify that the value assigned to a variable consists of
alphabets, letters or characters. In order to specify a variable as string type, we write ‘str’ in the
program. For example:
str a=”harsh”
str b=’samaira’
In the above statements, a and b are the variables, str is the data type(specifying that the value
of variable contains letters). The string value must always be written inside “ “ or ‘ ‘ .
It is used to print a message or any kind of text as a result. The message to be printed doesn’t
need to be in any specified format as it can be whatever you want. The syntax is as follows:
Example 2: a=10
b=20
c=25
print(a,b,c)
To print the values of different variables at the same time, you must use the (,) separator inside
print() function.
In order to tell the computer that a user wants to provide his input/ value, this function is used. It
is used to accept the value of a variable from the user. The data type of the variable can be
specified using int() or float() functions.
Here, A is the variable name for which we are asking the value from the user. The above
statement will take the input as a STRING type. If we want to take input as integer or float type,
then we need to write the code as follows:
sum= a+b
In the above program, a and b are the variables for which an input is taken from the user. The
int() function is used to specify that the values entered by the user will be of numeric form. Later
the ‘sum’ variable is written to perform the computation of addition. At last, the sum is printed in
the given format.
Python program to add two numbers without user input:
a=10
b=20
sum=a+b
print(sum)
In the above program, the values of the variables a and b are written by us in the program itself.
Hence it is directly printed on the screen as a result.