Python Beginner Notes
Python Beginner Notes
Text written in a program but not run by the computer is called a comment. Python
interprets anything after a # as a comment. Comments
Print
In Python, the print() function is used to tell a computer to talk. The message
to be printed should be surrounded by quotes. Print is also used in calculations.
Strings
Computer programmers refer to blocks of text as strings. In our last exercise, we
created the string “Hello world!”. In Python a string is either surrounded by double
quotes ("Hello world") or single quotes ('Hello world'). It doesn’t
matter which kind you use, just be consistent.
Variables
Programming languages offer a method of storing data for reuse. If there is a
greeting we want to present, a date we need to reuse, or a user ID we need to
remember we can create a variable which can store a value. In Python, we assign
variables by using the equals sign (=).
Variables can’t have spaces or symbols in their names other than an underscore
(_). They can’t begin with numbers but they can have numbers after the first
Numbers
An integer, or int, whole number, no decimal point, A floating-point number, or a
Changing Numbers
Variables that are assigned numeric values can
be treated the same as the numbers
themselves. Two variables can be added
together, divided by 2, and multiplied by a third
Modulo (%)
Python offers a companion to the division operator called the modulo operator.
Modulo operator is indicated by % and gives remainder of a division calculation. If
the number is divisible, then the result of the modulo operator will be 0.
Concatenation
The + operator doesn’t just add two
+= (plus-equals) also
can be used for string
concatenation: We create
social media captions,
but then update caption
to include important tags
Multi-line Strings
Python strings are very flexible, but if we try to create a string that occupies
multiple lines we find ourselves face-to-face with a SyntaxError. Python
surroundings. In Python, your script will execute from the top down, until there is nothing
left to run. It is your job to include gateways, known as conditional statements, to tell
the computer when it should execute certain blocks of code. If these conditions are
met, then run this function.
Boolean Variables
True False when typed in (uppercase T&F), they appear in different colors cuz they
are a special type of their own: bool. no quotation marks, must capitalize 1st letter!
True and False are the only bool types, and any variable that is assigned one of
these values is called a boolean variable.