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
Exampl
"Wajid e
"Ali"
" +
"WajidAli
"
Combined = "Wajid" & "Ali"
Exampl
"Wajid e
"Ali"
" +
"WajidAli
"
Combined = "Wajid" + "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
)
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