1/57
week 1
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
program
is a set of instruction given to a computer in a programming language to solve a problem
programming
is the process of writing an algorithm for the computer to program / act of writing a program
programming language
language that the computer understand
algorithm
set of instructions written
process of program execution
input —>process data internally —> output
note to remember
A = 65 B=66 C=67
What is Python?
a general purpose and high interpreted language
4. History
python was inverted in 1980s/1990s by Guido Van Rossum
Programs Are Text Files
we store python program as test files in extension .py
Name Origin
it was named after Monty python’s flying circus
IDE
integrated development environment e.g wing101
functions
code complier
debugging
print ()
built in function
print(“hello world”)
argument
"argument
value you pass in a function
comments
not for the computer
it always start with #
print(“name”)
When you call a function, the values you pass into it are arguments.
print(name)
When you define a function, the variables listed in the parentheses are parameters.
Logic errors
the program runs but doesn’t not work as expected
Syntax errors
it happens when the program doesn’t follow the programming rules e.i wrong structure and wrong spelling of key words and the program will not start at all
Escape Sequences
scape sequences are special character combinations
\n
newline
\’
prints ‘
\”
prints “
\a
makes a beep sound (bell)
\\
prints back slash \
\b
backspace — deleted the previous character in an output
example print(“Hello\b World”)
output — Hell World
\t
tab , leaves spaces
example print("Name\tAge\tCity")
output — Name Age city
integer
whole number
floating n
fractional number
Integers: Literals
fixed value written into a code
example numeric literals 1; 2
common operations
precedence of operations
high ()
middle % * /
last + -
//
division for integers
that is 3//2 = 1 {floor division}
integer operand
it simply means a whole number
modulus (%)
remainder
5%2 = 1
2%4 = 2
Identifiers
names used to identify variables; functions; classes and modules
Rules for Naming Identifiers
never start with numbers
start with underscore _ or letters
it can be followed by numbers
hyphens - are not allowed
no spaces
🚫 Invalid characters in identifiers:
@
(at symbol)
#
(hash)
$
(dollar sign — except in some languages like JavaScript or PHP)
!
, ?
, &
, +
, -
, *
, /
, etc.
Reserved Words (Keywords)
words that can not be used as identifiers
Attempting to use reserved words as identifiers will result in a syntax error.
variables
name section memory used to store data
zenora03 = “Botha”
note
Normally, print
adds a newline character (\n
) after printing, which moves the cursor to the next line.
sep=’*’
you have to put * between each value and not spaces
end= ‘‘
telling python not to add a newline or space after
prompt
text asking user for input
eval()
a function that converts strings into a number
Increment
x=10
x+=2
x=x+2
x=12
decrement
x=10
x-=2
x=x-2
x=8
Implicit Type Conversions (Type Coercion)
Python promotes int
to float
in operations if needed.
Explicit Type Conversions (Type Casting)
You can manually convert data types using built-in functions:
note
floats do not become int()
math.ceil
round up
math.floor
rounds down
Comment
a part of code starting with # and is for human reading
Function
performs collective purpose
Identifier
used to name variables and functions
Variable
container for date and named using identifier rules
String literal, numeric literal
fixed words or values used directly
arithmetic operators
-
+
*
/
Syntax
The fundamental rules of a programming language ▪ Similar to the spelling and grammar rules of natural languages