Core Elements of Programs Flashcards
What are the types of programming language?
Compiled (High level language)
Instructions are converted to low level ahead of time
Interpreted (Low level language)
Instructions are processed on the fly at the basic level of the computer
Interpreted (High Level language)
Instructions are processed on the fly at a high level which enables more abstract computation
What is a program?
A program/script is a sequence of definitions and commands. It manipulates data objects.
Definitions are evaluated.
Commands are are executed by the shell.
What is a shell?
Provides access to operating system services.
What is a command?
A command/statement instructs the interpreter to do something.
What are the types of data objects?
Scalar: int (5, 47)
float (4.7, 3.14)
bool (True, False)
NoneType
Non-scalar:
What is an expression?
Composed of operators and data objects.
What arithmetic operators are used on ints and floats?
i+j - Sum i-j - Difference i*j - Multiplication i/j - Division i//j - Division (int) i%j - Remainder i**j - Power
What comparison operators are used on ints and floats?
i>j - Greater than
i>=j - Greater than or equal to
i
What logic operators are used on bools?
a and b - True if both are True
a or b - True if either are True
not a - True if a is False, False if a is True
What are type conversions?
float(3) = 3.0 int(3.4) = 3
How do you bind values to variables and names?
=
What is operator overloading?
Using the same operator to achieve different things based on the type of object.
Depending on the type of the object, number or string the operator will decide what the right operation is to do.
What is string indexing vs slicing?
Indexing selects an individual letter from a string of characters
Slicing selects a portion of a string
How do you index an individual character from a string?
‘abc’[2]»_space;> ‘c’
How do you slice a set of characters from a string?
‘Python’[1:5]»_space;> ‘ytho’
‘Python’[0:0:2]»_space;> ‘Pto’
How do you denote a comment in a script?
#
How do you prompt for user input?
name = raw_input(‘Enter your name:’)
What are the syntax for nested conditionals?
if - checks a specific value
elif - checks a specific value if not already found
else - default if no criteria are met