Python Flashcards
Why Python?
- Python is a mature language, created by Guido Van Rossum in 1991
- Lots of libraries and very useful in data science community
- Documentation is constantly updated
- Huge community
- Easy to learn with readable syntax
Why version 3.6 and not 2.7?
Changes are very minimal. Support for 2.7 ends in 202, Most libraries are now written in 3.6. Improvements in print function, range function and division.
What is a web server?
A computer system that processes HTTP requests.
What is the HTTP response?
HTML, CSS, and Javascript
Where is python running?
On the server,. Python Django framework for example, will handle logic of what to do with each HTTP request and what to return in the HTTP response.
What is the HTTP request?
An HTTP client sends an HTTP request to a server in the form of a request message which includes the following format:
- A request-line
- zero or more header fields followed by CRLF
- An empty line indicating the end of the header fields
- Optional message body
Request-Line
The Request-Line begins with a method token, followed by the Request-URI and the protocol version, and ending with CRLF. The elements are separated by space SP characters.
How do we run Python code?
Within a python shell directly or save the code to a file that ends in .py file extension and tell python to run that file from our terminal.
What type of language is python?
An interpreted language, although it does compile our code into bytecode .pyc to be run in the python shell from time to time.
What is OOP?
stands for Object Oriented Programing, it is an important paradigm in which data and certain methods can be contained within objects.
What are the advantages of OOP?
Helps us DRY out our code.
Forces you to plan ahead which leads to higher quality code.
Don’t need to know how an object works exactly to use it.
If you need to change the code you can change the object itself and not hunt down every use of the object in your project.
Widely used in web design and game design.
Most frameworks use OOP.
How do we make (instantiate) an object?
create the variable and assign it to the class.
student1 = Student(“Janet”, “janet@gmail.com”)
How do we write a class?
Class Student: def \_\_init\_\_(self, name, email): self.name = name self. email = email self.numberofBelts = 0
def addBelt(self): self.numberofBelts +=1 return self
def say(self, thing): print(self.name, "says", thing) return self
What is self?
self is whatever that object happens to be. Think of it as a placeholder for the names of the objects that we will be making.
What are the attributes in the class Student?
The attributes are the variables: self.name, self.email
What are the methods in the class Student?
addBelt() and say()