1-First Python Program: Python Programming - (Install Python & Pycharm) Min 00:01
1-First Python Program: Python Programming - (Install Python & Pycharm) Min 00:01
Print (‘O-----‘)
Print (“ ||||’) program to draw a simple dog.
Print (‘*’ * 10) program to multiply character (‘*’) 10 times
Where the (“???“) (‘???‘) Define the item between
Them as a string as a character. And the (*) define
A multiply math operation. This ( ‘*’ * 10) is called a
Code expression
2- Variables
Price=10 price=20 name = ‘Mohammed’ rating=4,9 is_published = True
Print (price) Print (price) Print (name) Print (rating) print (is_new)
Solution / the executer runs smoothly that mean that the cods that is written have no error
.full_name = ‘Mohammed’
age=30
is_new=True
*Variables name written is small liter python is case sensitive language so like when you wright
Boolean in small liter like this true or false the python doesn’t recognize it so wright form is
True or False .
In this program we store simple values like integers, floats, string, Boolean
(10 , 4.9 , Ahmed , True) .
Solution/
print(age)
after execute
type error ( unsupported operand type -: ‘int’ and ‘str’ integer is a full number 2019 and
string is a character ’ Birth year’ its like we ar subtracting integer from a string and python
don’t now what to do or haw to evaluate this expertion ( 2019 - ‘1990’) to fix this problem
we nead to convert ‘1990’ into integer 1990 and then we can subtract i- we learned till now
to built in function that is print() and input() we have a few more function for converting
values
we have int() for converting string into an integer float() for converting string into afloat
bool() for converting string to a Boolean value so to fix the upper problem
we wright line 2 like this age = 2020 – int( birth_year ) int()will convert the birth
year to an integer so the python can evaluate the expression
we right before line 2 print(type of (birth_year)) and after line 3 print (type(age))
we see it appear like this <class ‘str’> <class’int’> so we learn wen aver we use the
input() function we goat a string so if you expect a numerical value you need to convert that
string into an integer or a float
ex3/ wright a program
Solution
5- Strings
Course=’python for beginners’
We use single or double ‘ ’ “ ” to define a string but sometimes you will use a specific
form so if we put like this Course=’python’ s course for beginners’ we se it only define
python as a string and don’t know what to do with the rest so we wright double cot ”” the
true form will be like this .
Print (course) (so if you put a double “ “ hear before beginner like this:
Course =”python’ s course for” beginners” we see that the python got confused and
don’t know what this characters (beginners)are so we change the double Quote to single
Quote like this
‘’’
course=’Python course for beginners’
print(course[0]) Output = P
Here we can use brackets [ ] to gets a character and give an index to this string the index of
the first character in this string in other word this is haw python string are indexed 012345 so
the index of the first character is 0 and so on So if we run the program we get P also we can
use negative index here if we use negative index we see the characters starting from the end
assuming 0 is the index of the first character so -1 is the index of the last character so in -2
we get the second character from the end Print(course[-1]) Output = s
Print(course[-2]) Output = r Pay attention to this brackets [ ] and haw it works
because it’s used in python online and university tests all so we can use this syntax to extract
more character rather than one character for example Print(course[0 : 3]) output = Pyt
will return the character from index 0 to index 3 but exclude the character of index if we use
[0 : ] python will return all the character from the string output Python course for
beginners if we use [ 1 : ] python will exclude the first character like this output = ython
course for beginners if we use it like this [ : 5 ] python will assume the start index is 0
and the output = Pytho if we put it like this [ : ] python will assume the start index is 0 and
the end index is the end of the string . so we can basically copy or clone a string .
If we define another variable here like this after the (course) variable in the example above
variable (another) will be a copy of the variable ( course )
Ex
ex/ define a variable called name and set it to Jennifer and index it like like this 1 : -1
and see the solution
name = ‘jennifer’
first = ‘john’
last =’smith’
message= first + ‘ [ ’+last+’ ] is a coder ’
msg = f‘ {first} [ { last} ] is a coder ‘
print(message) output = John [smith] is a coder
print(msg) output = John [smith] is a coder
min 40:50