Sei sulla pagina 1di 2

1. Python allows you to change the data type assigned to a variable.

For example, x=Pranay is


the first assignment and say it is printed and you get the output. Then the datatype assigned
next to x need not be a string now. It can be any of the possible data types supported by x.
So I can assign x=123 and print x and still not get any syntax error or something.
2. type() function can be used to detect the type of the argument. For example, type(Pranay)
returns that the argument is of datatype str ( meaning string), type (1234) returns that the
arguemtn is still of datatype str( 1234 is in quotes), type(3.14) float, type(123)- int.
3. + operator can be used to add int, floats etc etc and also used concatenate strings.
4. Variables help us reuse the code
5. Two types of errors in a python are the syntax errors and name errors. Syntax errors are
caused if you are not properly following the python grammar and name errors are caused if
a name is not defined previously or if you are using the keywords with wrong names
( capitalization etc etc)
6. Variable names cannot start with a number. They can start with an underscore though. They
cannot start with @,!,#,$,%,& either
7. input() statement can be used to ask the input from the user. No matter what you give as
input, it will always be stored as string. Input() command prints anything that is typed in as
argument, reads the inputs from user and stores in the variable to which you want to assign.
For example, name = input(what is your name) prints what is your name and when you
type your name ( or whatever the shit you want to type) it is stored in the name variable.
8. Using commas in a print statement does the job of spacing between the strings for you. For
example, print(hey,bro) echoes hey bro. Comma print formatting can also be used to
combine strings and numbers in print statement which cannot be done using the
concatenation operator(+)
9. To change to new line, youll have to use \n in your print statement. For example,
x=3;y=3;print(x is ,x,\n,y is,y,\n) prints x is 3 and in a new line y is 3
10. To print quotes in a string, we make use of the the two types of quotes, single and double.
You can put double quotes in a single quote statement to print the double quotes and vice
versa
11. isalpha() method when invoked on a string return either true/false depending on whether
the string on which the method is invoked is composed entirely of alphabets only or not
(remember space is not an alphabet)
12. isalnum()-whether alphanumeric or not.
13. Startswith(<any letter>)-true if the string starts with the argument letter ( remember that it
is case sensitive)
14. islower() and isupper() methods are used to check if a string is completely lower cased or
completely upper cased
15. istitle() checks if every word separated by space in your string is upper case or not
16. title() method changes the first letter after every space in the string to capital
17. isdigit() method checks if all the string is comprised entirely of digits
18. lower() method allows the change the entire string to lowercase whereas upper() method
allows us to change the entire string to upper case
19. capitalize() basically just capitalizes the first letter of the first word in the string. It doesnt
matter if the string has more than one sentence. It just cares about the first word in the
string and it capitalizes the first letter of that word. If the stirng initially had any capitalized
letter theyll all be lowercased.
20. swapcase() is used to convert lower to upper and vice versa
21. you can actually format of the stirng from user right away by invoking the above methods
directly on input() command. For example, input(favourtie color?).upper()
22. in keyword is used to search a particular word in a string. If it exists then you get a true
value. If it doesnot you get a false value. If you are not that particular about case sensitivity,
you can invoke lower() on both the target and the search string. For example, menu=this is
SPArta; print(sparta.lower() in menu.lower()) gives true.
23. type() takes exactly one argument and returns it type. However it doesnt return the value to
standard output but rather you should store it in a variable.
24. To define a function we use the keyword def. syntax is def function_name(): observe the
colon it is very important. Function name should start with an alphabet or underscore
25. You can call a function by function name followed by parenthesis.
26. Function parameters allows data to be passed to and used by functions.
27. You can assign default values to the parameters of your function so that when the function is
called without any parameters it takes the default values as arguments. For example, def
say_this ( phrase =good night) takes default value of phrase as good night and does the
corresponding task. However if you explicitly specify what phrase is supposed to take while
calling the function, the function will do the task using the explicitly mentioned argument as
the parameter
28.

Potrebbero piacerti anche