Python Flashcards
How do you keep the output of the next print on the same line?
end=’ ‘ inside of print()
EX: print(‘Hello there.’, end=’ ‘)
newline character escape sequence
\n
tab escape sequence
\t
print(‘Name\tJob’)
Name Job
\ escape sequence
\
escape sequence
two item sequence used to add in a special character such as new line, tab, and other symbols that may be used for other things in the language that need to be used as a literal, like ‘ “ \
a \ starts the escape sequence so it knows to use the next character literally
raw string
Escape sequences can be ignored using a raw string. A raw string is created by adding an “r” before a string literal, as in
r’this is a raw string'’
which would output as
this is a raw string'
convert string to int
int()
wage = int(input())
ask user for input and convert it to int
hourly_wage = int(input(‘Enter hourly wage: ‘))
syntax error
violates a programming language’s rules on how symbols can be combined to create a program
runtime error
program’s syntax is correct but the program attempts an impossible operation
logic error
aka a bug - a logical flaw
what are scripting languages used for?
to execute programs without the need for compilation
script
file that contains code designed to be executed directly
A script is a Python file (ending in .py) that contains code designed to be executed directly. When you run a script, the Python interpreter reads and executes all the lines in the file.
Use Case: Scripts are typically used for programs meant to be executed as standalone applications, such as automating tasks, running data analysis, or simple command-line programs.
garbage collection
Deleting unused objects is an automatic process that frees memory space
type()
returns the type of an object.
Mutability
indicates whether the object’s value is allowed to be changed
immutable
integers and strings are immutable; meaning integer and string values cannot be changed. Modifying the values with assignment statements results in new objects being created and the names bound to the new object.
id()
gives the value of an object’s identity
Properties of objects
Value: A value such as “20”, “abcdef”, or “55”.
**Type: ** The type of the object, such as integer or string.
Identity: A unique identifier that describes the object, which is usually the memory address where the object is stored.
floating-point number (float)
real number, like 98.6, 0.0001, or -666.667. The term “floating-point” refers to the decimal point appearing anywhere (“floating”) in the number