Exam 1 Flashcards
If I have a file, testFile.py, what do I type in Command Window to run the file; if I use IDLE, what key do I press on the keyboard to run the file?
Python testFile.py; For IDLE, press F5.
What are the characteristics of machine language, assembly language, and high-level language?
Machine: 1s and 0s
Assembly: Symbols (Need an assembler)
High-level: Close to spoken language use complier or interpreter
Is Python a compiled or interpreted programming language? What’s the difference?
Python is interpreted programming language. Interpreted programming can do one line at a time.
Python interpreter can be used in two modes, what are they?
Interactive and script modes
Comments in Python begin with what symbol?
#
To display multiple items with a single print, you use ___ to separate items.
,
How to get input values from the user in Python? How to convert the input strings to numbers?
Input function always get a string. num=int(input(‘ ‘)), num=float(input(‘ ‘)).
Math operators in Python? Two types of division? Exponentiation? Remainder? Their order of precedence?
Order of Operations: (), **, *, /,//, %, +, -
Floating division: /
Integer division: //
Answer the following in order
16/3
16//3
16/(-3)
16//(-3)
5.333
5
-5.333
-6
What is 150 % 8
Use long division for this, the answer is 6
What are the data types learned in class?
int: integer
float: float
str: String
bool: Boolean
What are the restrictions for variable names?
Variable name cannot be a Python key word
Variable name cannot contain spaces
First character must be a letter or an underscore
After first character may use letters, digits, or underscores
Variable names are case sensitive
What is the assignment operator? Difference between = and ==?
= is the assignment operator. == on the other hand determines whether two variables are equal.
What is 1001011 in both decimal and hexadecimal?
Decimal is 71.0
Hexadecimal is 4B
Multiline continuation character in Python?
/
What does end=’delimiter’ and sep=’delimiter’ do?
end=’delimiter’: causes print to place delimiter at end of data instead of newline character.
sep=’delimiter’: causes print to use delimiter as item separator
How to format output using the format function?
Format (area, ‘.2f’)
What are the possible format specifications in print?
%.2f: float
%d: int
%s: str
What are the possible escape sequences?
\n: new line
\t: tab
What is a boolean expression? Relational operators and logical operators in Python?
Boolean Expression: Tests if a statement is true or false.
> : Greater than
<: Less than
=: Greater than or equal to
<=: Less than or equal to
==: Equal to
!=: Not equal to
How do you access individual characters in a string?
StringV[0] -> len(StringV)
You use what operator to concatenate strings?
+ operator
What are the augmented operators in Python?
*=
/=
%=
How to get the substring of a string?
StringV[start:end:step]
What are some other string methods?
isalnum: True if all characters in the string are letters or digits
isalpha: True if all characters in the string are only letters.
isdigit: True if all characters in the string are only numbers
islower: True if all letters in the string are lowercase
isspace: True if all characters are whitespace
isupper: True if all letters in the string are capitalized.