100% de satisfacción garantizada Inmediatamente disponible después del pago Tanto en línea como en PDF No estas atado a nada 4,6 TrustPilot
logo-home
Notas de lectura

Class notes Computer Science

Puntuación
-
Vendido
-
Páginas
118
Subido en
30-04-2025
Escrito en
2024/2025

extensive python notes from beginner to advanced

Institución
Grado











Ups! No podemos cargar tu documento ahora. Inténtalo de nuevo o contacta con soporte.

Escuela, estudio y materia

Institución
Grado

Información del documento

Subido en
30 de abril de 2025
Número de páginas
118
Escrito en
2024/2025
Tipo
Notas de lectura
Profesor(es)
Ken
Contiene
Todas las clases

Temas

Vista previa del contenido

3/25/2021 Python - Jupyter Notebook




Prepared by Asif Bhat

Python Tutorial
In [103]: import sys
import keyword
import operator
from datetime import datetime
import os



Keywords

Keywords are the reserved words in Python and can't be used as an identifier


In [3]: print(keyword.kwlist) # List all Python Keywords

['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'cl
ass', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'fr
om', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or',
'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']


In [4]: len(keyword.kwlist) # Python contains 35 keywords
Out[4]: 35



Identifiers

An identifier is a name given to entities like class, functions, variables, etc. It helps to differentiate
one entity from another.


In [13]: 1var = 10 # Identifier can't start with a digit

File "<ipython-input-13-37e58aaf2d3b>", line 1
1var = 10 # Identifier can't start with a digit
^
SyntaxError: invalid syntax




In [14]: val2@ = 35 # Identifier can't use special symbols

File "<ipython-input-14-cfbf60736601>", line 1
val2@ = 35 # Identifier can't use special symbols
^
SyntaxError: invalid syntax



localhost:8889/notebooks/Documents/GitHub/Public/Python/Python.ipynb 1/118

,3/25/2021 Python - Jupyter Notebook


In [15]: import = 125 # Keywords can't be used as identifiers

File "<ipython-input-15-f7061d4fc9ba>", line 1
import = 125 # Keywords can't be used as identifiers
^
SyntaxError: invalid syntax




In [16]: """
Correct way of defining an identifier
(Identifiers can be a combination of letters in lowercase (a to z) or uppercase (
"""

val2 = 10

In [17]: val_ = 99



Comments in Python
Comments can be used to explain the code for more readabilty.


In [18]: # Single line comment
val1 = 10

In [19]: # Multiple
# line
# comment
val1 = 10

In [20]: '''
Multiple
line
comment
'''
val1 = 10

In [21]: """
Multiple
line
comment
"""
val1 = 10


Statements

Instructions that a Python interpreter can execute.




localhost:8889/notebooks/Documents/GitHub/Public/Python/Python.ipynb 2/118

,3/25/2021 Python - Jupyter Notebook


In [27]: # Single line statement
p1 = 10 + 20
p1

Out[27]: 30


In [28]: # Single line statement
p2 = ['a' , 'b' , 'c' , 'd']
p2
Out[28]: ['a', 'b', 'c', 'd']


In [26]: # Multiple line statement
p1 = 20 + 30 \
+ 40 + 50 +\
+ 70 + 80
p1
Out[26]: 290


In [29]: # Multiple line statement
p2 = ['a' ,
'b' ,
'c' ,
'd'
]
p2
Out[29]: ['a', 'b', 'c', 'd']



Indentation

Indentation refers to the spaces at the beginning of a code line. It is very important as Python uses
indentation to indicate a block of code.If the indentation is not correct we will endup with
IndentationError error.


In [37]: p = 10
if p == 10:
print ('P is equal to 10') # correct indentation
P is equal to 10

In [38]: # if indentation is skipped we will encounter "IndentationError: expected an inde
p = 10
if p == 10:
print ('P is equal to 10')
File "<ipython-input-38-d7879ffaae93>", line 3
print ('P is equal to 10')
^
IndentationError: expected an indented block




localhost:8889/notebooks/Documents/GitHub/Public/Python/Python.ipynb 3/118

, 3/25/2021 Python - Jupyter Notebook


In [39]: for i in range(0,5):
print(i) # correct indentation
0
1
2
3
4


In [43]: # if indentation is skipped we will encounter "IndentationError: expected an inde
for i in range(0,5):
print(i)
File "<ipython-input-43-4a6de03bf63e>", line 2
print(i)
^
IndentationError: expected an indented block




In [45]: for i in range(0,5): print(i) # correct indentation but less readable

0
1
2
3
4


In [48]: j=20
for i in range(0,5):
print(i) # inside the for loop
print(j) # outside the for loop
0
1
2
3
4
20



Docstrings

1) Docstrings provide a convenient way of associating documentation with functions, classes,
methods or modules.

2) They appear right after the definition of a function, method, class, or module.


In [49]: def square(num):
'''Square Function :- This function will return the square of a number'''
return num**2




localhost:8889/notebooks/Documents/GitHub/Public/Python/Python.ipynb 4/118
$99.99
Accede al documento completo:

100% de satisfacción garantizada
Inmediatamente disponible después del pago
Tanto en línea como en PDF
No estas atado a nada

Conoce al vendedor
Seller avatar
danielgoossens12

Conoce al vendedor

Seller avatar
danielgoossens12 tutorpro
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
0
Miembro desde
9 meses
Número de seguidores
0
Documentos
3
Última venta
-

0.0

0 reseñas

5
0
4
0
3
0
2
0
1
0

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes