Python crash course H1 +H2 Flashcards
(31 cards)
What is ipython?
The Python shell, a place where you can type Python code and immediately see the results. Kind of juiced up version of regular Python.
what are python scripts?
These python scripts are simply text files with the extension dot p y. It’s basically
a list of Python commands that are executed, almost as if you where typing the commands yourself.
Je slaat de python commands dus op.
What does ‘print’ do?
Print inside scripts if you want to generate output during execution.
variable
een variabele waar je data in kunt zetten. Bij voorbeeld variabele ‘lengte’ –> alle lengtes van de personen in de dataset.
what is a float?
a real number in python (21,98)
what is a int?
a integer in python (heel getal)
What is a string? (str)
a string is pythons way to represent text (single en double quotes (haakjes) werken)
What is a boolean? (bool)
Een binomiale waarde. True or false. Goed voor filteren van operations on your data.
What is syntax highlighting?
Text editor of terminal weet welke taal je gebruikt. (kleuren eraan geven in sublime)
Hoe creeer je een variabele ‘message’?
message= ‘hello world’ (daarna print(message))
Variabelen kunnen zowel text als nummers hebben. Maar mag de variabele zowel met getallen als text beginnen?
Nee je moet met text of underscore beginnen. 1_message kan dus niet!
Is het toegestaan om in de variabele naam een spatie toe te voegen?
nee. Dit moet vervangen worden door een underscore _
Wat is een traceback?
Een traceback ontstaan wanneer je een error hebt gemaakt. Het is een vastlegging van waar de error precies heeft plaatsgevonden toen je de code wilde uitvoeren.
Een name error wat is dat?
De variabele heeft geen waarde toegekend gekregen of jij hebt de verkeerde naam ingevoerd waardoor de variabele niet bestaat.
welke line gebruik je om je code te laten werken in terminal?
Je moet je terminal niet op python3 zetten. Dan doe je cd (dit betekent change directory) en dan type je de locatie van je folder waar je .py in zit. Dan print je de file door python … file name…. in te typen.
wat is een string?
A string is simply a series of characters. Anything inside quotes is considered a string in Python, and you can use single or double quotes around your strings.
Wat doet de functie ‘title’ in een print context?
Het zorgt er voor dat van de string een titel wordt gemaakt en daarmee hoofdletters aan de beginletters wordt gegeven.
wat is een method?
A method is an action that Python can perform on a piece of data. The dot (.) after name in name.title() tells Python to make the title() method act on the variable name. Every method is followed by a set of parentheses, because methods often need additional information to do their work. Een method past dus eigenlijk het gene wat je wilt printen aan. (.upper of .lower = hoofdletters of kleine)
waarom is de lower method handig?
Many times you won’t want to trust the capitalisation that your users provide, so you’ll convert strings to lowercase before storing them.
what is concatenation?
het combineren van string. Dus full_name= first_name +’ ‘ + last_name (let op die spatie die er tussen moet)
vb: print(“Hello, “ + full_name.title() + “!”)
what is whitespace?
refers to any nonprinting character, such as
spaces, tabs, and end-of-line symbols. You can use whitespace to organize
your output so it’s easier for users to read.
wat doet /t in je print sentence?
Het voegt een ‘tab’ toe. Dus een stuk wit
wat doet /n in je print sentence?
Het plakt de message op de volgende regel.
what does .rstrip(), .lstrip() of .strip() (method) do?
It eliminates the whitespace at the end or begin of a sentence. (rechts of links) (tijdelijk, dus alleen voor die print situatie) Wil je dat hij het voor altijd weg haalt. Dan moet je de method in de variabele gebruiken: favorite_language = favorite_language.rstrip()
Als je hierna print(favorite_language) doet geeft hij geen white space.