Python 3

Objects

Everything in Python is an Object

Objects are data structures, a way of storing digital information. A Data type

A number (numerical) is a different data (text) type than text

Strings an object to store text, 0 or more characters. Anything typed with keyboard
Literals a piece of syntax that creates an object
Example of Strings Single or Double Quotes
"apple"
'apple'

String: An immutable (can not be changed after creation) sequence of text characters (any Unicode text to include spaces). Just plain text to Python. A space is a valid character, zero character strings are also possible, Strings with zero characters.
Example of Empty Strings Single or Double Quotes
""
''

A string with a numerical value are not the same as a number. 1st Example a sting (text object) 2nd is number (numerical)
"7"
7

Triple Quotes block strings, multi line strings with breaks (documentation strings). Break up text across multiple lines.
""" Text here, and
here and here and here
"""

Functions

Procedure a series of instructions, steps, do things in order. Order is important.

A collection of organized Python code that can be reused, capture logic an drepeat the function. Instead of having to rewrire

2 Types; 1) Builtin (Print) 2) Custom developer defined

Inputs (Arguments) and Outputs (Return Values)

A function can accept Inputs and Output

Arguments – Outputs are return values

Functions are called, executed – invoke the Function to run or execute.

Print Function

Output to screen

Float Objects have decimals
print("A", "B")
print("C", "D", "E", "F")

print(1 + 1, 2 + 2, 3 + 3)

#Float Example with decimal
print("Good Morning", 1.23)

Function Parameters and Arguments

Parameter: A name for an expected argument to a function. A configuration setting, keyword parameters.

sep=” is a default argument, single space. SEP defines the seperator
print("C", "D", "E", "F", sep="!")
print("C", "D", "E", "F", sep="")

*** look out for quotes in strings or apostrophes. Wrapping in double quotes usually works.
print(*objects, sep='', end='\n', file=sys.stdout, flush=False)

Print objects to the text stream file, separated by sep and followed by end. sep, end, file and flush, if present, must be given as keyword arguments.

All non-keyword arguments are converted to strings like str() does and written to the stream, separated
by sep and followed by end. Both sep and end must be strings; they can also be None, which means to
use the default values. If no objects are given, print () will just write end.

The file argument must be an object with a write(string) method; if it is not present or None,
sys.stdout will be used. Since printed arguments are converted to text strings, print () cannot be used
with binary mode file objects. For these, use file.write(…) instead.

Whether output is buffered is usually determined by file, but if the flush keyword argument is true, the
stream is forcibly flushed.

Mathematical Expressions

This will print Hello 99 times, concatenation
print("Hello" * 99)

This is exponential, 5 to the power of 3
print(5 ** 3)

Prioritizing calculations with Parenthesis
print(3 + 5 * 3)
print((3 + 5) * 3)

Division

print(14 / 3)

Floor Division
print(14 // 3)

The Boolean Data Type

The Equality Operator (==) and Inequality Operator (!=)

A Data type that is true or false

print(1 == 1.0)
print(2 == 2.1)

print(True == True)
print(False == False)
print(True == False)

print(10 != 8)
print(10 != 10)
print("music" != "music")
print("music" != "noise")
print("music" != "Music")

print(10 != "10")
print(8.3 != 9.8)
print(3.0 != 3)

Variable

Name assigned to the object, name for a given value, name that refers (reference) to the object

Name = "Eddie"

name = “Eddie”
age = 19
handsome = True
favorite_language = “Python”

print(name)
print(handsome)
# print(occupation)

Python reserved keywords can not be variable names

and
assert
break
class
continue
def
del
elif
else
except
exec
finally
for
from
global
if
import
in
is
lambda
nonlocal
not
or
pass
print
raise
return
try
while

This command reveals where Python3 is located
which python3

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
Share via
Copy link