0% found this document useful (0 votes)
2 views

Basic Python (D)

The document outlines essential topics for a Python course, including Python basics, sorting algorithms, object-oriented programming, data structures, file processing, and recursion. It emphasizes Python's case sensitivity, variable declaration rules, data types, and the use of comments. Additionally, it provides practice questions to reinforce learning on variable assignment, string concatenation, and user input handling.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Basic Python (D)

The document outlines essential topics for a Python course, including Python basics, sorting algorithms, object-oriented programming, data structures, file processing, and recursion. It emphasizes Python's case sensitivity, variable declaration rules, data types, and the use of comments. Additionally, it provides practice questions to reinforce learning on variable assignment, string concatenation, and user input handling.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

PYTHON

9618

MAY JUNE 2023


THINGS WE NEED TO COVER

PYTHON BASICS
BUBBLE SORT AND INSERTION SORT
OBJECT ORIENTED PROGRAMMING
ADT (STACKS QUEUE LINKED LIST BINARY TREE)
FILES PROCESSING AND EXCEPTION HANDLING
RECURSION
PYTHON
IT IS CASE SENSITIVE LANGUAGE
NO DATATYPES DECLARATION
NO REPEAT UNTIL
NO CASE OFF
INDENTATION IS VERY IMPORTANT
PRINT FUNCTION

OUTPUTS THE TEXT OR ANY INFORMATION STORED IN A VARIABLE

SYNTAX
print("Enter text here")
print(x)
VARIABLES
PYTHON HAS NO COMMAND FOR DECLARING A VARIABLE.
A VARIABLE IS CREATED THE MOMENT YOU FIRST ASSIGN A
VALUE TO IT.

YOU ARE SUPPOSE TO DECLARE THE VARIABLES IN COMMENT AS


IT IS THE REQUIREMENT FOR YOUR EXAM

COMMENTS
#THIS IS A COMMENT
RULES FOR THE NAME OF VARIABLE

VARIABLE NAME SHOULD BE SENSIBLE


A VARIABLE NAME MUST START WITH A LETTER
OR THE UNDERSCORE CHARACTER
A VARIABLE NAME CANNOT START WITH A
NUMBER
A VARIABLE NAME CAN ONLY CONTAIN ALPHA-
NUMERIC CHARACTERS AND UNDERSCORES (A-
Z, 0-9, AND _ )
VARIABLE NAMES ARE CASE-SENSITIVE (AGE,
AGE AND AGE ARE THREE DIFFERENT
VARIABLES)
VALID EXAMPLES

sum = 0 Sum = 0 _sum1 = 0

INVALID EXAMPLES

1sum = 0 sum-1 = 0 sum 1 = 0


DATATYPES

String (str) : "Text "

Integer (int) : Numbers

Float : Real Numbers


CONVERTING DATATYPES

Number 1 = 5.456
print(type(Number1))
type() is a function that returns the Datatype

NumberInteger = int( Number1)


print(type(NumberInteger))
MATHEMATICAL OPERATORS

Addition +
Subtraction -
Division /
Multiplication *
Practice Question

Assign 50 in a variable (Num1) multiply that


number with 40.45 and store the solution in a
variable (Answer) and print only the integer part
of the Answer with a relevant message and
declare all the variables used
STRING CONCATENTAION

String : Any text in speech marks ""

Concatenation : Link together


Example
"Taha" + "Ali"
"TahaAli"

Combined = "Taha" & "Ali"


Example
"Taha" + "Ali"
"TahaAli"

Combined = "Taha" + "Ali"


Practice Question
Assign your First Name in a variable
(String1) and your Second Name in a
variable (String2) and combined both of
the string with space between them and
store it in a variable (Combined_String )
INPUT FROM THE USER

Number = input("Enter Number")


Note: In python input function always returns string
value so if it's a number then you are suppose to
change it into integer or float
PRACTICE QUESTION

Ask two numbers from the users and


add both of the number and print
the Answer with a relevant message

You might also like