0% found this document useful (0 votes)
7 views10 pages

Python Programming Basics Explained

Uploaded by

lucky778200
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views10 pages

Python Programming Basics Explained

Uploaded by

lucky778200
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Main points: Lesson 1

Syntax-the set of rules that define the structure and format of code in a
programming language

SYNTAX is the simple way to perform a task

EX- typed - print ("Welcome")

Result – welcome

The print() is the simple way to display the message on the screen

Parentheses – () parentheses are used for order of operations, or


order of evaluation, and are referred to as tuples
Quotation marks are important to display the text ,so the main point is
to display a screen with the help of : print ("Welcome")
But , when the no. came the Quotation marks are not included : EX;
print(980)
Human use code to give instructions to machines.
Print(“”)is important to display messages on screens.

Lesson 2
VARIABLES program is used to save important information.

EX: item = "bike"

In it ITEM is called variable used for a thing

There are various types of VARIABLES.

Like: country= “France” and etc.

The VARIABLE is dependent upon the categories you choose for coding.

 The computer variables programs uses to remember important information.


 A variable has a name and value.

 You can create a variable by the name and the value with an EQUAL SING (=)

LESSON 3
A piece of text data is called a STRING

STRINGS in python are need to be surrounded by QUOTATION MARKS


we use quotation marks to tell the python that we are working with a piece of text
data ( STRING )

In Python both QUOTATION MARKS are used to define STRINGS.

Item = "bike" is called statements I python.

Lesson 3
Numerical data – it is information that comes in form of numbers.

Like; population = 250000

Numerical – is that in which quotation marks are not present.

Ex; house = 511

(*) – is which represents multiply symbols in python.

budget = 200

print(budget)

what will be display on the screen ?

 Print
 Budget
 200 right

 Numerical value cannot be surrounded by quotation marks.


Lesson 4
To store variable in no

Ex’; Age =34

Budget = 20

Print (budget + 10)

What value will be displayed on screen?

 Print
 20
 30 right

Means that we can represent calculated no by coding

Reassigning – it means that a value of a variable is updated.

Like; points = 35

points = 45

print(points)

The screen will represent 45 then 35 because the value of variable is updated.

Lesson 5
Debugging – it is a term given to fixing errors

Coding contains three steps:

1. Writing
2. Executing
3. debugging

code execution can be interrupted by bugs.


Lesson 6
We can add comments in our python code by HASH SYMBOL (#)

Comments- it is used for adding description or explanation about our program.

Like; # displaying a message

Print (“insufficient balance”)

We can use comments for temporarily disable a statement

EX: #print ("Game Over")

“The code cannot show the command on screen because of hash symbol (#).”

 Python is a very sensitive language because it understands different


in A and a.

Snake case is a very popular way to create variable names in a consistent way.

It uses underscore (_) to separate words in variable name.

Lesson 7
A variable name cannot be start with a number

Like: 3user_id – it will result as error

Lesson 8
user_entry = input()

It means “ask the user for a value that gets stored in a variable called
user_entry”

Input () – it stands for store a command that is given.

Print () – is used for output


 Inputs and outs help machine to communicate with the outside world.

Lesson 9
Data comes in various shapes and different forms.

String is a Data type because it contains Quotation marks

In coding language Integers contains only of negative and positive number


without decimal.

EX: 3 not 0.03

Float – it is a data type that contains both decimal and –tive and +tive

EX: -7 or 5.007 or 4

Concatenation – when two strings are joined together

Like: a = "basket"

b = "ball"

Print (a+b)

Result – basketball

Lesson 10
We can correct a data by type ()

Balance = "780"

type(balance)

type() is used when the types of data comes it is very useful for correcting a error or
debugging.

It helps to verify a data type.

 The division of two integers is called float


Lesson 11
 If we store a numerical value with a string the value would not be able to
do math’s

We can a convert a string into integer by:

EX; a= “13”

b=int(a)

The result will be display as an integer.

Lesson 12
We can convert data type by following instruction:

Int() – it converts a variable into integer

Str() – it converts a variable into string

Float() – it converts a variable into float

Lesson 13
Comparison operation – we compare a number or variable and computer gives the
statement that it is true or false.

Computer uses binary code to represent information;

By 1 = ON and 0 = OFF

Lesson 14
Logical operation – needed for the machine to evaluate the complex values
Logical operation uses Boolean value

It takes several Boolean as input and produce only one Boolean as output

And operation – results in a true value only when all the inputs are true at the same
time

Or operations – results in a results in a true value at least when the one value is true

Lesson 15
True and True = True

Every other combination = False

Computer is capable of making decisions, because they are very good at following
instructions.

To learn the flow of instruction usually follows three steps:

1. Sequencing
2. Iteration
3. Selection

Sequencing:
It means that the computer runs your code in order, from top to bottom.

Like: print("3")

print("building")

print("blocks")

Results – 3

Building

Blocks

Hence, it is in sequence. That’s why it is called Sequencing.

Iteration:
Iteration is about executing an instruction repeatedly. Iteration is commonly
represented as a loop.
Listening a song repeatedly is an example of Iteration.

Selection:
Selection specifies when to follow each path. Smart watches notify the wearer if their heart rate
goes outside the normal range. This is an example of Selection.

Algorithm:
An algorithm is a set of step-by-step instructions to complete a task, placed in a certain order.

Algorithms can be represented in many ways.

For example, flowcharts help to visualize algorithms.

Note:- Comparison and logical operations are needed to control the flow of your programs.

Another way to represent an algorithm is with pseudocode.

Pseudocode:

Pseudocode is a simplified language that is a bit closer to a programming language.

Takeaways of this lesson:

🌟 You use sequencing, iteration and selection to control the flow of instructions
🌟 An algorithm is a set of step-by-step instructions to complete a task
🌟 Algorithms can be represented in different ways

Lesson 16
In this lesson we will learn to create loops (Iteration).

For loop : It is used with the keyword ‘for’. The variable i keeps track of the number of
iterations.

Example: for i in range(100):

Print("Hello")

Results in 100 times of hello.

The code that gets repeated in the for loop must be indented.
Indented: Indentation is the spaces at the beginning of lines.

Lesson 17
While loops are powerful because they can be used even when you don’t know how many
iterations will be needed.

While loop begins with keyword While.

Loops usually include counters

Counters- A counter is a variable that keeps track of the number of iterations.

Lesson Takeaways:
🌟 You can apply iteration to your programs with the while loop
🌟 counters keep track of the number of iterations and avoid infinite loops
🌟 Indentation and the colon: symbols are required for the code to run

Lesson 18
You know how many iterations:
For loop
You don’t know how many iterations:
While loop

You might also like