PythonBasics Flashcards
print working directory
pwd
my computer’s network name
hostname
make directory
mkdir
change directory
cd
list directory
ls
what should you do if you get lost in terminal?
write “pwd” to print working directory and next “cd ~ ” to get back to home
How do you create a folder with multiple words in the name?
write mkdir for creating a folder and then put “” around the name. For example,…. Mkdir “that’s pretty cool”.
remove directory
rmdir
What does “cd ..” do?
it takes you back one folder from for example /desktop/temp/stuff to /desktop/temp, This can also be done for multiple folders back with ../../.. (3 folders back)
What does CLI mean?
Command line interface
What does GUI mean?
graphical user interface
What will “ls -1R” do?
it will show you an overview of all folders below your current position.
push directory
pushd (go to new location)
pop directory
popd (return to saved location)
what does “mkdir -p” do?
lets you create an entire directory at once aka. Multiple folders in a tree. Mkdir -p kap/jokap/chakap/ja/sådan/er/det
copy a file or directory
cp
move a file or directory
mv
What can be the problem if you are not allowed to rmdir a directory?
First of all there could be files within that folder you try to delete. Secondly, if you are 100 % sure that there is nothing, it may be due to the Mac OSX issue of an “.DS_Store” file, which you can delete by going to the folder and write “rm -rf .DS_Store”
page through a file
less
print the whole file
cat
What will
mkdir something
cp awesome.txt something/
Do?
first we create a new folder/directory. Next we make a copy of the file awesome.txt from current pwd to this new folder called “something”
create a new file
touch (write…. “touch iamcool.txt” for example)
How do we copy a file?
go to the directory of the file and write “cp filename.txt newfilesname.text”
execute arguments
xargs
find files
find
how do you rename a file?
use mv (move a file) so you write “mv filename.doc newfilename.doc”. you can check the name change after by listing the directory content with ls
how can you see the content of a file?
write “less filename.txt” and it will show you the content. To quit, just type q
How can you remove a FILE?
just write “rm filename.doc” (you can also remove multiple files at once by listing them)
How can you remove a folder/directory?
rmdir foldername
How can you delete a file within a folder?
rm foldername/filename.txt
How can you delete a folder that contains files?
rm -rf foldername
Whats the “execute” command?
xargs
find things inside files
grep
read a manual page
man
find what man page is appropriate
apropos
look at your environment
env
print some arguments
echo
export/set a new environment variable
export
exit the shell
exit
What is the command to become a super-user?
sudo makes you a super-user and lets you force through more commands
Which command can you use to change the access permissions to a file?
chmod
How can you change the file owner?
use chown
How do you run a python file from terminal?
Just write “python filename.py”
What does # do in python and what is it called?
A hash.
If you put a hash (#) in front of a line of code, it will not print / go in effect so you can use it for making comments
How can you print a hash/octothorpe? “#”
you put it inside strings; print “we have a # inside of the strings now” # the hash inside the strings will be printed but this comment after the second # will not be printed.
What is / called and what is it?
slash and it is the division sign
What is * called and what is it?
asterisk and it is the multiplier sign
How do you make additions?
with “+” for example “print 3 + 2” will output 5
How do you make subtractions?
with “-” for example “print 3 - 4” will output -1
What is “%” and what does it do?
percent and it works as ‘X divided by Y with J remaining’. For example, “100 divided by 16 with 4 remaining” so print “100 % 16” will be 4. While 100 % 10 will be 0.
What are floating point number?
Essentially just numbers that include decimals such as 5.5 or 0.02
What output will print “20/3” give?
6… if you want the precise output including decimals you need to write print “20.0/3.0) and you will get 6.666666666666667
how do you write less-than-equal?
<=
how do you write greater-than-equal?
>=
What is the order of mathematical operations?
PEMDAS, Parentheses, exponents, multiplication, division, addition, subtraction
How do you create a variable in python?
you basically just write out with a “=” sign in-between so for example,
“Cars = 100” # creates a variable that ‘cars’ is equal to 100
“cars_not_driven = cars – drivers” # creates a variable for available cars (cars_not_driven)
What is the difference between = (single-equal) and == (double-equal)?
The = (single-equal) assigns the value on the right to a variable on the left. The == (double-equal) tests if two things have the same value.
Can we write x=100 instead of x = 100?
You can, but it’s bad form. You should add space around operators like this so that it’s easier to read.
How do you define number and character variables?
Examples…
My_name = “Lars Horsbol”
And
My_age = 23
How do you insert variables inside printed text?
you use %s for character-variables and %d for number variables. For example,
Print “Let’s talk about %s” % my_name
And
Print “He’s %d centimeters tall.” % my_age
How should you refer to a number-variable inside printed text?
With %d
Print “He’s %d centimeters tall.” % my_age
How should you refer to a character-variable inside printed text?
With %s
Print “Let’s talk about %s” % my_name
How do you add variables together inside printed text?
You just write them out in the %d.
print “If I add %d, %d, and %d I get %d.” % (my_age, my_height, my_weight, my_age + my_height + my_weight)
here we are trying to add the variables together
How does the %r format work?
If you use %r, it will print no matter what, meaning that it will both print a character-variable (normally %s) and a number-variable (normally %d).
print “and with both character %r AND number %r” % (height, hair) # with %r we will end up printing both the character-variable AND the number-variable
and with both character 192 AND number ‘Dark-blond’
What are the different conversion types in Python and which ones are most common?
%d = signed integer decimal
%s = character-variables
%r = ”print this no matter what”
What’s the point of %s and %d when you can just use %r?
The %r is best for debugging, and the other formats are for actually displaying variables to users.
Can I make a variable like this: 1 = ‘Zed Shaw’?
No, the 1 is not a valid variable name. They need to start with a character, so a1 would work, but 1 will not.
How can we insert a number inside “x = “There are %d types of people” ?
We write “% 10”
x = “There are %d types of people.” % 10 # here we write a string and insert a variable with % outside the string
How can you combine two strings such as:
w = “this is the left side of…“
e = “a string with a right side.” ??
just write; print w + e
How can I round a floating point number?
You can use the round() function like this: round(1.7333) or round(weight / pounds_to_kilo)
Can I use single-quotes or double-quotes to make a string or do they do different things?
In Python either way to make a string is acceptable, although typically you’ll use single-quotes for any short strings like ‘a’ or ‘snow’ and double-quotes for sentences.
Should I use %s or %r for formatting?
You should use %s and only use %r for getting debugging information about something. The %r will give you the “raw programmer’s” version of variable, also known as the “representation.”
Why do you put ‘ (single-quotes) around some strings and not others?
Mostly it’s because of style, but I’ll use a single-quote inside a string that has double-quotes. Look at line 10 to see how I’m doing that.
print “I also said: ‘%s’.” % y
What will; print “.” * 10 do?
this will result in 10*. So the output will be; ……….
If, end1 = “C”
end2 = “h”
end3 = “e”
end4 = “e”
end5 = “s”
end6 = “e”
end7 = “b”
end8 = “u”
end9 = “r”
end10 = “g”
end11 = “e”
end12 = “r”,
what will;
print end1 + end2 + end3 + end4 + end5 + end6
print end7 + end8 + end9 + end10 + end11 + end12
result in?
Just.
Cheese
burger
On two different lines because there is no comma after “end6”.
Why do I have to put quotes around “one” but not around True or False?
That’s because Python recognizes True and False as keywords representing the concept of true and false. If you put quotes around them, then they are turned into strings and won’t work right.
If, end1 = “C”
end2 = “h”
end3 = “e”
end4 = “e”
end5 = “s”
end6 = “e”
end7 = “b”
end8 = “u”
end9 = “r”
end10 = “g”
end11 = “e”
end12 = “r”,
what will;
print end1 + end2 + end3 + end4 + end5 + end6,
print end7 + end8 + end9 + end10 + end11 + end12
result in?
Just.
Cheese burger
On two different lines because there is a comma after “end6” it stays on the same line in the printed output.
What will; print “Its fleece was white as %s.” % ‘snow’ result in?
Its fleece was white as snow.
If you have; formatter = “%r %r %r %r” , what will happen if you write print formatter % (formatter, formatter, formatter, formatter)
‘%r %r %r %r’ ‘%r %r %r %r’ ‘%r %r %r %r’ ‘%r %r %r %r’
If you have; formatter = “%r %r %r %r” , what will happen if you write;
print formatter % (
“I had this thing.”,
“That you could type up right.”,
“But it didn’t sing.”,
“So I said goodnight.”
)
‘I had this thing.’ ‘That you could type up right.’ “But it didn’t sing.” ‘So I said goodnight.’
Why do I have to put quotes around “one” but not around True or False?
That’s because Python recognizes True and False as keywords representing the concept of true and false. If you put quotes around them, then they are turned into strings and won’t work right.
I tried putting Chinese (or some other non-ASCII characters) into these strings, but %r prints out weird symbols.
Use %s to print that instead and it’ll work.
Why does %r sometimes print things with single-quotes when I wrote them with double-quotes?
Python is going to print the strings in the most efficient way it can, not replicate exactly the way you wrote them. This is perfectly fine since %r is used for debugging and inspection, so it’s not necessary that it be pretty.
Why do the \n newlines not work when I use %r?
That’s how %r formatting works; it prints it the way you wrote it (or close to it). It’s the “raw” format for debugging.
What are two ways to make a string that goes across multiple lines?
- You can use \n è “nJan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug”
- You can use a triple double quote “”” ………… “””
What will making three double-quotes allow you to do? “”” “””
Write a lot of text within the “”” here “”” on multiple different lines
print “””
There’s something going on here.
With the three double-quotes.
We’ll be able to type as much as we like.
Even 4 lines if we want, or 5, or 6.
”””
How do you write some text that is tabbed in?
Like this?
You use; \t so for example
Print “\tI’m tabbed in.”
How do you write a string of text and then split the text on different lines?
You use \n so for example…
Print “I’m split\non a line.”
Will become;
I’m split
On a line
What will; print “I’m \ a \ cat.” ; result in?
I’m \ a \ cat
So it removes one of the backlashes
How can you produce a list of points?
What does the escape sequences \ do?
What does the escape sequence \’ do?
What does the escape sequence; \a do?
It inserts an extra space.
So;
Print “hey man\a whats up”
Becomes
Hey man whats up
What does the escape sequence \b do?
What does the escape sequence \n do?
What does the escape sequence \r do?
What does the escape sequence \t do?
When I use a %r format none of the escape sequences work.
That’s because %r is printing out the raw representation of what you typed, which is going to include the original escape sequences. Use %s instead. Always remember this: %r is for debugging; %s is for displaying.
What is the function of the comma in this:
print “How old are you?”,
age = raw_input()
the function of the comma is to make sure that the output is on the same line.
With comma we get; How old are you? 23
Without comma we get: How old are you?
23
What is raw_input in python and what is it useful for?
Raw_input lets you interact with the outside world to get input. The raw_input() function waits for the user to type some input and press return. It then gets whatever was typed.
(called input() in python 3 but here it also tries to convert the input whereas rawinput from python 2 simply takes the raw input which is usually easier to work with/safer)
How can you insert prompts for raw_input requests?
Just write questions or prompts inside the string of the raw_input() like this;
height = raw_input(“How tall are you? Fx. 1.82 m”)
How can you look up what any function in python does from within the terminal?
Why would I use %r over %s?
Remember, %r is for debugging and is “raw representation” while %s is for display. I will not answer this question again, so you must memorize this fact. This is the #1 thing people ask repeat- edly, and asking the same question over and over means you aren’t taking the time to memorize what you should. Stop now, and finally memorize this fact.
What do you also call a “.py” file?
A script
What are modules?
Modules are features you can add in your python script. Some people also called modules for libraries.
It could for example be: sys and argv
Python filename.py arg1 arg2 arg3
So for example
Python e13.py I want snacks
Will give…
The script is called: e13.py
Your first variable is: i
Your second variable is: want
Your third variable is: snacks
What happens if you input less arguments for argv when trying to run in the command line?
What’s the difference between argv and raw_input()?
The difference has to do with where the user is required to give input. If they give your script inputs on the command line, then you use argv. If you want them to input using the keyboard while the script is running, then use raw_input().
How can you use raw_input prompts for multiple places in your script?
Does txt = open(filename) return the contents of the file?
No, it doesn’t. It actually makes something called a “file object.” You can think of it like an old tape drive that you saw on mainframe computers in the 1950s or even like a DVD player from today. You can move around inside them, and then “read” them, but the file is not the contents
What does from sys import argv mean?
For now, just understand that sys is a package, and this phrase just says to get the argv feature from that package. You’ll learn more about these later.
Why is there no error when we open the file twice?
Python will not restrict you from opening a file more than once, and in fact sometimes this is necessary.
Which command will let you close files?
Close
Which command will let you read files?
Read
Which command will let you open files?
Open
Which command will let you read just one line?
Readline
Which command will let you empty a file for its content? (be careful)
Truncate
Which command will let you write stuff into your file?
Write(stuff)
What could we write to open a file? (existing or not)
What could we write to open and read a file?
What does the file modes “r” do in python?
This is the default mode. It Opens file for reading.
What does the file modes “w” do in python?
This Mode Opens file for writing.
If file does not exist, it creates a new file.
If file exists it truncates the file.
What does the file modes “x” do in python?
Creates a new file. If file already exists, the operation fails.
What does the file modes “a” do in python?
Open file in append mode.
If file does not exist, it creates a new file.
What does the file modes “t” do in python?
This is the default mode. It opens in text mode.
What does the file modes “b” do in python?
This opens in binary mode.
What does the file modes “+” do in python?
This will open a file for reading and writing (updating)
How can you write a simple script that will open a file specified in command/terminal?
If you open the file with ‘w’ mode, then do you really need the target.truncate()?
No. It doesn’t make any difference as the “w-mode” will overwrite the existing file so emptying that file first makes no difference.
Does just doing open(filename) open it in ‘r’ (read) mode?
Yes, that’s the default for the open() function.
What can the “import” statement do?
With the import statement we can import new modules to python.
Some modules/functions are existing in your python program already, but sometimes you may want to add new functions. Here, it can be smart to import code written by others than to innovate yourself. You can import such new modules with the import statement.
Why do you have to do output.close() in the code when the file is already closed?
It is good practice to always close files so you avoid later commands working with those files from reading descriptions from those closed files.
What does the len() function do?
It gets the length of the string that you pass to it and then returns that as a number. Play with it.
What do functions do? (put simply)
- They name pieces of code the way variables name strings and numbers.
- They take arguments the way your scripts take argv.
- Using #1 and #2, they let you make your own “mini-scripts” or “tiny commands.”
Think of “function” as a mini-script
How do you create a function in python?
Write; def (for define)
The first function is overly complicated. It takes the look of when we work with args and does uses *args inside print_two. On the line below, it unpacks those args to finally print it.
There is no need to do this unpacking. We can simply put arg1, arg2 inside the function from the beginning.
How should you start a function?
- With; def (for definition)
- And then open paranteheses right after the function name
- And list the arguments comma separated
- End the parantehese AND add a colon:
def print_three(arg1, arg2, arg3):
How should your function name be?
It should only use characters AND underscore so for example
Print_two_again
How many spaces should the lines of code in a function be indented?
4 characters. No more, no less.
This usually happens automatically in your script-writing program
How do you end a function? (stop adding more to it)
What does it mean to run a function?
The same as to “use” or to “call” a function
What does it mean to call a function?
The same as to “run” or to “call” a function
What does it mean to call a function?
The same as to “use” or to “use” a function
What’s allowed for a function name?
Just like variable names, anything that doesn’t start with a number and is letters, numbers, and underscores will work
What does the * in *args do?
That tells Python to take all the arguments to the function and then put them in args as a list. It’s like argv that you’ve been using, but for functions. It’s not normally used too often unless specifi- cally needed.
Are functions and variables connected?
No. The functions you write in your script are not connected to the variables.
it will print:
We can just give the function numbers directly:
You have 20 cheeses!
You have 30 boxes of crackers!
Man that’s enough for a party!
Get a blanket.
As it will first “We can just give the function numbers directly:” and then all the content of the function (def) Cheese_and_crackers below it.
How should you write up an user-input-variable making sure that it will be an integer result?
Put raw_input inside int() for integer
For example
Eaten_packages = int(raw_input(“How many packages did you eat by now? “))
Is there a limit to the number of arguments a function can have?
It depends on the version of Python and the computer you’re on, but it is fairly large. The practical limit, though, is about five arguments before the function becomes annoying to use.
What does f.seek do?
The seek-function takes the “cursor” (or point of the mouse so to say) to a certain place in a file. For example, we take it to the very beginning with f.seek(0) so we are at the start of the file again
What does += do?
+=
adds another value with the variable’s value and assigns the new value to the variable.
+=
adds a number to a variable, changing the variable itself in the process (whereas +
would not).
It adds the right operand to the left. x += 2
means x = x + 2
What does -= do?
+=
subctracts a number from a variable, changing the variable itself in the process (whereas -
would not).
It subtracts the right operand from the left. x -= 2
means x = x - 2
What does *= do?
*=
multiplies a number with a variable, changing the variable itself in the process (whereas *
would not).
It multiplies the right operand with the left. x *= 2
means x = 2x
What does /= do?
/=
divides a variable with a number, changing the variable itself in the process (whereas /
would not).
It divides the right operand with the left. x /= 2
means x = x/2
What does %= do?
%=
finds modulus of a variable with a number, changing the variable itself in the process (whereas %
would not). Modulus = the remainder when dividing.
It finds modulus so: x %= 3
means x = modulus of x/3
How does readline() know where each line is?
Inside readline() is code that scans each byte of the file until it finds a \n character, then stops reading the file to return what it found so far. The file f is responsible for maintaining the current position in the file after each readline() call, so that it will keep reading each line.
What does the return statement do/how does it work?
The RETURN statement writes out what it does to the user AND can also be used by other functions
The PRINT statement simply writes out what’s inside but cannot be used by other functions
Example explanation:
Def returnFunction(num):
Num = num *2
Return num
Def printFunction(num):
Num = num *2
Print(num)
If we write…
returnFunction(4)
we get an output of; 8
if we write….
printFunction(4)
we get an output of; 8
So as such they look the same.
But.. heres the difference.
X = returnFunction(4)
X #notice this one
8
Y = printFunction(4)
8
So the return function gives us “x” but the print-function doesn’t give us anything so we cannot use it later.
If we in python now ask for x we will get 8 but if we ask for y we won’t get anything.
How can I use raw_input() to enter my own values?
Remember int(raw_input())? The problem with that is then you can’t enter floating point, so also try using float(raw_input()) instead.
What does “return” mean?
It’s the same as “output”. Synonyms.
How do you write comments in python?
Write # and everything here after the hashtag will not be shown. It is called HASH or and OCTOTHORPE
But you can still write an octothorpe inside strings like:
Print “here we # like to go on Instagram”
How do you print some text that is followed by maths?
Remember to put a comma…
Print “Hens”, 25 + 5
Will return
Hens 30
Or
Print “What is 3 + 2?”, 3 +2
Will return
What is 3 + 2? 5
How do we create a variable in python?
Simple use =
For example
Cars = 100
What does %r do?
If you use %r, it will print no matter what, meaning that it will both print a character-variable (normally %s) and a number-variable (normally %d).
print “and with both character %r AND number %r” % (height, hair) # with %r we will end up printing both the character-variable AND the number-variable
and with both character 192 AND number ‘Dark-blond’
How can we repeat a printed string?
Just write asterisk and the number of times you want to repeat it. For example:
Print “.” * 20
Will return
………………..
How do you write a list of things but on different lines?
Use \n
For example:
Months = ‘Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug’
Print “Here are the months: “, months
How can you tab in some printed text?
Use \t
So for example
Print “””
I’ll do a list:
\t* Sugar
\t* Spice
\t* And everything nice
Will return
I’ll do a list
- Sugar
- Spice
- And everything nice
How can you ask users to input information/answer questions?
Use raw_input()
For example…
Print “How old are you?”,
Age = raw_input()
remember the comma after print
What do you need to do before you can use arguments?
Import argv by writing…
From sys import argv
Can you write strings inside raw_input()?
Yes. This is called a prompt. Help for the answer
For example
Print “What’s your birthday? “,
Raw_input(“DD-MM-YYYY” )
How do you define what your arguments are?
Write first the argument inoputs such as…
Script, filename = argv #script name and filename is defined here.
How can we create AND open a file at the same time?
note… you must define filename.
Open(filename, “w”)
How do you delete the contents of a file?
Target.truncate()
How do you write something into a file through your script?
Target.write()
How do you close a file?
Target.close()
How do you create a line break?
\n
How we get the number of bytes a file is long?
Len()
How do we open and read a file in the same line of code?
note you must define from_file
open(from_file, “r”)
How do you tell python that there is a function inside a certain file?
First you open command and run “python”
Then you “import file1” (whatever file it is)
And then tell python to run a certain function within “file1” by adding “dot” and the function’s name. For example:
E25.print_last_word(sorted_words)
How do you incorporate help statements in your python functions and later display them in command?
break_words(stuff)
This function will break up word for us.
print_first_and_last(sentence)
Prints the first and last words of the sentence.
print_first_and_last_sorted(sentence)
Sorts the words then prints the first and last one.
print_first_word(words)
Prints the first word after popping it off.
print_last_word(words)
Prints the last word after popping it off.
sort_sentence(sentence)
Takes in a full sentence and returns the sorted words.
sort_words(words)
Sorts the words.
What is a list?
lists
- consist of a countable number of ordered values
- fruits = [’orange ’ , ’apple ’ , ’pear ’ , ’banana ’ , ’kiwi’, ’apple’, ’banana’]
What is a tuple?
- Immutable: Cannot be changed
- The advantage is that you will know the position of the elements better and thus also make it easier for the computer to locate elements: provides for speed
- You use it when you know that a variable will not change (e.g. days of the week)
- Values are separated by commas
- v = (’a’, ’b’, ’c’)
What is a set?
sets
- unordered collection
- NO duplicate elements
- basket = {’apple’, ’orange’, ’apple’, ’pear’, ’orange’, ’banana’}
What is a dictionary?
dictionary
- a set of keys: value pairs in which each key is unique
- tel = {’jack’: 4098, ’john’: 4139}
What are classes and objects/instances?
classes are used to create new user-defined data structures that contain arbitrary information about something. Class is generic.
- Class: Dog
- species = ’mammal ’
an object/instance is a copy of the class with actual values (thus you have 1 class and multiple instances). Object/instance is specific.
- Instance/object:
- def __init__(self , name, age): self .name = name
- self .age = age
Will these two turn out the same results?
What is the difference between for- and while loops?
- For-loops you know in advance the number of times it will execute. This is unknown with while-loops as it executes as long as the Boolean condition is True
- Use a for-loop for definite iterations = if you know the maximum number of times that you need to execute the code
- Use a while-loop if you require to repeat some computation until a condition is met that you cannot calculate in advance (needed for probabilistic results and human intervention)
what does a break statement do?
a break statement is used to immediately finish a loop.
(this is considered bad practice though)
what does a continue statement do?
a continue statement causes to skip the processing of the rest of the code for a loop BUT the loop continues with the subsequent iterations of the loop
(this is considered bad practice though)
What does “syntax error” refer to?
- Missing punctuation characters, such as parentheses, quotation marks or commas
What does “TypeError” refer to?
- when you try to combine to incompatible items
What does “NameError” refer to?
- Normally when you have used a variable before assigning it a value
What does “ValueError” refer to?
- When the value passed to a function is not compatible with the function.
- in the example as string inserted as if it was to be converted to an integer
What is the standard format to ask for help in programming communities?
TIRTBV
- Title
- Introduce
- Reproduce (others should be able to reproduce)
- Tags
- Background
- Version
How can you take the sqrt of numbers in python?
What is the difference between “a = 2” and “a == 2”?
A = 2 is defining a as 2
A == 2 is asking whether a is equal to 2 or not
What are 3 good rules for naming variables?
- Names can not start with a number
- Use _ when using space
- Do not use capital letter (best practice is lowercase)
What are the 3 types of variables?
- Float
- Integer
- Boolean
How do you make addition, subtraction, multiplication, diversion, power functions and modulo?
- Addition (i.e. +)
- Substraction (i.e. -)
- Multiplication (i.e. *)
- Division (i.e. /)
- Power functions (i.e. **)
- Modulo (i.e. %)
What is a possible reason why (0.1+0.2-0.3) equals 5.551115123125783e-17 instead of 0?
The numbers have not been rounded and are only showing with one decimal.
To turn to 0 write: round(0.1+0.2-0.3)
How do you get the number of characters in a string?
Count number of characters in “Hello world”
my_text = ‘Hello world’
len(my_text)
11
What will….
my_text = ‘Hello world’
print(my_text[7])
return?
O
H = 0, e = 1, 2 = l, 3=l, o=4, “ “ = 5, w=6, o=7
If, my_text = ‘Hello world’, how can you write it out as both capital letters, small-case letters and as two different strings?
How can you reverse the order of a list?
If…
a = {‘a’,’b’,’c’,’d’}
b = {‘b’,’c’,’e’}
find all the elements in a and b result={‘a’, ‘b’, ‘c’, ‘d’, ‘e’}
a | b
If.. my_list = [1,2,3,4,2,2,2,2,5,5,5,5,9,9,9] how do we find the number of unique elements and how do we create set of these unique numbers?
len(set(my_list))
6
set(my_list)
{1, 2, 3, 4, 5, 9}