Chapter1-3 Flashcards
Checking python version?
ust type python on command line , u will see the version
How to start python on terminal?
start terminal
ii. Type python to start python
Write ur program
best way to name python variable ?
- The Python variables you’re using at this point should be lowercase. You won’t get errors if you use uppercase letters, but it’s a good idea to avoid using them for now.
What is python traceback?
A traceback is a record of where the interpreter ran into trouble when trying to execute your code. e.g Traceback (most recent call last):
u File “hello_world.py”, line 2, in v print(mesage)
wNameError: name ‘mesage’ is not defined
What does name error means?
A name error usually means we either forgot to set a variable’s value before using it, or we made a spelling mistake when entering the variable’s name.
A string
you can use single or double quotes around strings
This exibility allows you to use quotes and apostrophes within your strings:
whet is title() function?
title() function convert first letter if each word in string to capital
how to strip whitespaces?
u strip whitespce using rstrip() e.g avorite_language = ‘python ‘ . favorite_language.rstrip() remove the whitespace after n
lstrip()?
strip whitespace from the left side of a strin
how to strip whitespace from both sides?
use strip()
What is syntax error?
A syntax error: A syntax error occurs when Python doesn’t recognize a section of your pro- gram as valid Python code. For example, if you use an apostrophe within single quotes, you’ll produce an error.
print in python 2 and 3 ? what is relation?
In python 2 , printing is not necessary u can type print “isa Musa”. In python 3 , some code u will see print with parenthesis some without parenthesis
does python concatenate numbers with string?
Pyhon don’t concatinate numbers with string unless u change the numbers to string
error
Integers in Python 2 ?
result to an integer
Division of integers in Python 2 results in an integer with the remainder truncated. Note that the result is not a rounded integer; the remainder is simply omitted.3/2 in python returen 1 make sure to use float
How to comment in python?
Comments using #
What is the zen of Python ?
Experienced Python programmers will encourage you to avoid com- plexity and aim for simplicity whenever possible. The Python community’s philosophy is contained in “The Zen of Python” by Tim Peters
how to open zen of python?
You can access this brief set of principles for writing good Python code by enter- ing “import this” into your interpreter.
what Is a list?
A list is a collection of items in a particular order. You can make a list that includes the letters of the alphabet, the digits from 0–9, or the names of all the people in your family. List items don’t have to be related in any order. Because a list usually contains more than one element, it’s a good idea to make the name of your list plural, such as letters, digits, or names.
How to create a list?
In Python, square brackets ([]) indicate a list, and individual elements in the list are separated by commas bicycles = [‘trek’, ‘cannondale’, ‘redline’, ‘specialized’]
how to access a List ?
Accessing Elements in a List A[0]
where index position start in python?
Index Positions Start at 0, Not 1
Accesing last item in list
1) A[-1] , we use -1 to access the last item in a list
how negative list acess useful?
This syntax is quite useful, because you’ll often want to access the last items in a list without knowing exactly how long the list is. This convention extends to other negative index values as well. The index -2 returns the second item from the end of the list, the index -3 returns the third item from the end, and so forth.
How to modify element in list?
motorcycles[0] = ‘ducati’