Module 1 Flashcards
Language
a means for expressing and recording thoughts
Machine language
very rudimentary computer language
binary language (0s and 1s)
it is the language that computers understand at their core
Natural language
languages that develop organically, naturally
human language
What are the 4 parts of a language?
alphabet
lexis
syntax
semantics
what is a language’s alphabet?
a set of symbols used to build words of a certain language
what is a language’s lexis?
a set of words the language offers its users
a dictionary
what is a language’s syntax?
a set of rules used to determine if a certain string of words forms a vali sentence
what is a language’s semantics?
a set of rules determining if a certain phrase makes sense
instruction list
complete list of known commands for a computer
alphabet of a machine language
is the Instruction List - the computer’s mother tongue
these are sets of symbols that we use to give commands to a computer (through a high-level language like Python)
High level programming language
java, python, javascript, c#, etc.
a programming language designed to be easier for humans to understand and write, using syntax closer to natural language, rather than the low-level machine code of a computer
source code
a program written in a high-level programming language
source file
the file containing the source code
in other words a file containing a program written in high-level programming language
compilation
the source program is translated to machine language
This action must be repeated each time you modify the source code
This means the program can be distributed as an executable file to be run on other computers
C#, C++, Java
interpretation
the source code is read into machine code each time the program is run
the downside is that whoever is running the program must have the interpreter installed to run it
Python, JavaScript
computer program is actually just a …
pure text file (no decorations, like fonts colors embedded images, or other media)
interpreted languages are also known as
scripting languages
Python creator
Guido van Rossum
Guido van Rossum
the creator of python
CPython
The default implementation of the Python language – the one that is downloaded from Python.org
The canonical version
written and maintained by the Python Software Institute (PSF) of which, Guido is president
Written in the C programing language
Cython
translates python code into C
What does the interpreter do?
It directly executes instructions written in a programming language.
It reads the high level programming language and translated it into low level machine code
Specifically, it reads the source code from left to right top to bottom as is common in western culture and uncovers errors as it goes.
the first error it encounters, it finishes its interpretation of the code
Advantages of compilation
execution of the translated code (the code that is translated to machine language) is generally faster
only the user (the programmer) needs to have the compiler. The end-user gets the translated file
The translated code is stored as machine language, and so it is very hard to understand it, so programming tricks can remain hidden
Disadvantages of Compilation
The complication is a time consuming process
you have to have as many compilers as hardware platforms you want your code to run on
Compiler catches only syntax and semantic errors while compiling. So other errors may not be found until runtime and may be hard to race at that point
Advantages of Interpretation
You can run the code as soon as you complete it
The code is stored as programming language (high level language) so you do not need a compiler for each type of system in order to disburse the code
In other words, it can be run on different computers that use different types of machine language
Disadvantages of Interpretation
Interpretation will take some CPU power, so an interpreted program will never be as fast or as efficient as a compiled program
Both the programmer and the end user need the interpreter in order to run the program
Not as secure as compiler because everyone can see the source code
Python rival languages?
Perl
ruby - more innovative than Python
Which Python does this course (2025) use?
Python 3
Jython
A Python written in Java instead of C
PyPy and Python
A Python environment written in Python
What do you need in order to work with Python?
Python must be installed on your computer
An editor which supports your code must be available
A console from which you can launch your code and stop it when there is a problem
A debugger which will allow you to inspect your code at each moment of execution
negative indexing
Negative indexing starts at -1
So, given
thisList = [‘hat’, ‘cat’, ‘mat’]
print(thisList[-1])
console:
mat
OR
thisStr = ‘a string here this is one’
print(thisStr[-1])
console: e
no start: no stop: step = -1 (flips the string)
print(thisStr[::-1])
console: eno is siht ereh gnirts a
Booleans
True
or
False
capitalized first letter
# so, true and false would result in NameErrors as Python would consider them unassigned variables
What does “pass” do?
Nothing. Nothing at all. A whole lotta nothing.
What does “continue” do?
Skips the current iteration of a loop and continues to the next iteration.
x = 0
while x < 8:
if x % 2 == 0:
continue
print(‘#’)
Also this wouldn’t work either, as the continue just skips the print
x = 0
while x < 8:
if x % 2 == 0:
continue
print(‘#’)
What does the bitwise left shift operator ( «_space;) do?
The bitwise left shift operator («) moves the bits of its first operand to the left by the number of places specified in its second operand
Shifting a single bit to the left by one place doubles its value
name this operator: «
bitwise left shift operator
What is the result?
2 «_space;5
64
Name this operator:»_space;
bitwise right shift operator
What does the bitwise right shift operator do?
The bitwise right shift operator (») moves the bits of its first operand to the right by the number of places specified in its second operand
Shifting a single bit to the right by one place halves its value
What does IDLE stand for?
Integrated Development and Learning Environment
What does a debugger do?
A tool that lets you launch your code step-by-step and inspect it at each moment of execution
What is the expected behavior of the following program?
prin(“Goodbye!”)
This program will generate an error
Specifically, a NameError (since the object “prin” is not defined
What is a console?
A command-line interpreter that lets you interact with your OS and execute Python commands and scripts
What is the best definition of a script?
A text file which contains instructions which make up a Python program
What is the expected behavior of the following program?
print(“Hello!”)
Prints
Hello!
to the console
What is the result of this program ? And why?
thisStr = “here it is”
print(thisStr[::-1])
si ti ereh
The string indexing resolves to:
[no start index : no end index : -1 step]
So it starts at the end of the string and steps backwards until the beginning