Python Flashcards
(39 cards)
What is Python?
Python is a high-level, general-purpose object oriented programming and scripting language.
What is a High-Level programming language?
A High-Level programming language is a language that has a lot Abstraction from the details of the computer. For example it will simplify or automate tasks such as Memory Management opposed to a low-level language that is usually less readable and requires direct code for dealing with the details of the computing system. Low and High are used to describe high abstraction and low abstraction.
How is a python variable declared?
variable = variable_value
what does the \ do in this statement:
‘Hi, I'm Anthony’
It is used to escape string and use a special character ( ‘ ) the example could also be written “Hi I’m Anthony” because double quotes were used around the string.
How do you create a single line comment in python?
By using the pound (hash) symbol.
How do you create a multiple line comment in Python?
”"”You start it with the quotation marks followed by the comment and then end the multi line comment with three more quotation marks”””
What does len( ) do?
len ( ) is a method that returns the string length of the string (including spaces) or variable storing a string that is passed to it.
What does upper( ) do?
It convert a string or variable storing a string to uppercase. It is written like this
“eggs”.upper( )
That would return “EGGS”
what does lower( ) do?
It converts a string or variable storing a string to lowercase. It is written like this:
“SpAm”.lower( )
that would return “spam”
What does str( ) do?
It converts what ever is passed to it into a string (accept variable names). it is written like this:
str(2.13)
Would return “2.13”
Why does lower( ) and upper( ) use dot notation?
lower( ) and upper ( ) are unique to strings so they use string literals where as len( ) and str( ) can be passed object that are not strings.
what does print do?
Print outputs the what it is passed to the console from the interpreter.
How do you concatenate string in python?
By using the plus sign (+).
“hello “ + “world”
what are PEPs?
Python Enhancement Proposals
What is the keyword to create a function?
def
What is a docstring?
is a triple quoted (“””) multi link comment that comes before the code block of the function but after the name that briefly explains what the function does.
What is a parameter?
a parameter is the what you place between the parenthesis when you define a function.
What is an argument?
An argument is the data that you put inside the parenthesis when you run or call the function.
What are “splat arguments” and how are they defined?
Splat arguments are when you don't know how many arguments a function will be passed so can't set up the number of parameter to match. The splat arguments gives you the ability to set a arbitrary place holder that accepts however many arguments are passed to it. it is defined like this: def funcName(*args): the_function The *args can be whatever you like but that is what is usually used.
What are the ways you can import modules?
- Generic Import
- Function Import
- Universal Import
What is a generic import?
You can import the entire module using “import module_name”. When using things from this module you will have to type it’s name again i.e. module_name.module_functionORvariable
what is a functional import?
Import a specific function or variable from a module. like this: from module_name import functionORvariable_name when this method is used you do not have to call the module name before using the function or variable.
What is a universal import?
A universal import is when you import all of the functions and variable of a module and dump them all over the place. from module_name import * this makes it so you do not have to type the module_name before the function or variable but is not good practice as it is easy for conflicts to occur.
What does min( ) do?
Return the smallest of the arguments passed.