• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 4 out of 68 pages
Class notes

Python language class notes (basic to advanced)

Document preview thumbnail
Preview 4 out of 68 pages

My detailed material include essential libraries like Pandas and NumPy for data manipulation and analysis, along with core Python concepts, file handling, object-oriented programming, and advanced modules. Perfect for students, these notes simplify complex topics with clear explanations, practical examples, and guides. Learn how to handle datasets, perform mathematical computations. Whether you’re a beginner or preparing for exams, these notes are tailored by me to boost your understanding and save time!"

Content preview

Programming with Python
notes basic to advanced with
coding challenges
Basic

Introduction:

Python is a very simple language, and has a very straightforward syntax. It encourages
programmers to program without boilerplate (prepared) code. There are two major
Python versions, Python 2 and Python 3. Python 2 and 3 are quite different. This tutorial
uses Python 3, because it more semantically correct and supports newer features.


Install Jupyter Notebook[2]
n this machine learning project for beginners, we will use Jupyter Notebook for the
development. Let’s see steps for the installation and configuration of Jupyter Notebook.

Using pip python package manager you can install Jupyter notebook:
In [ ]:
pip3 install notebook

And that’s it, you have installed jupyter notebook

After installing Jupyter notebook you can run the notebook server. To run the notebook,
open terminal and type:
In [ ]:
jupyter notebook

It will start the notebook server at http://localhost:8888
In [ ]:
!git clone https://github.com/hussain0048/Python.git

,1- Hello, World!
The simplest directive in Python is the "print" directive - it simply prints out a line (and
also includes a newline, unlike in C).For example, one difference between Python 2 and 3 is
the print statement. In Python 2, the "print" statement is not a function, and therefore it is
invoked without parentheses. However, in Python 3, it is a function, and must be invoked
with parentheses.
In [ ]:
#To print a string in Python 3, just write:
print("This line will be printed.")
In [ ]:
print("Goodbye, World!")
Goodbye, World!



2- Indentation
Python uses indentation for blocks, instead of curly braces. Both tabs and spaces are
supported, but the standard indentation requires standard Python code to use four spaces.
For example
In [ ]:
x = 1
if x == 1:
# indented four spaces
print("x is 1.")
In [ ]:
x = 1
if x == 1:



3 - Variables and Types
Python is completely object oriented, and not "statically typed". You do not need to declare
variables before using them, or declare their type. Every variable in Python is an object.

This tutorial will go over a few basic types of variables.



3.1 Numbers
Python supports two types of numbers - integers and floating point numbers. (It also
supports complex numbers, which will not be explained in this tutorial).

,To define an integer, use the following syntax:
In [ ]:
myint = 7
print(myint)
In [ ]:
#To define a floating point number, you may use one of the following
notations:
myfloat = 7.0
print(myfloat)
myfloats = float(7)
print(myfloats)

3.2- Strings
Strings are defined either with a single quote or a double quotes.The difference between
the two is that using double quotes makes it easy to include apostrophes (whereas these
would terminate the string if using single quotes)
In [ ]:
mystring = 'hello'
print(mystring)
mystring = "hello"
print(mystring)



4 -Lists
Lists are very similar to arrays. They can contain any type of variable, and they can contain
as many variables as you wish. Lists can also be iterated over in a very simple manner. Here
is an example of how to build a list.
In [ ]:
mylist = []
mylist.append("a")
mylist.append("b")
mylist.append("c")
print(mylist[0]) # prints 1
print(mylist[1]) # prints 2
print(mylist[2]) # prints 3
In [ ]:
# prints out 1,2,3
for x in mylist:
print(x)
In [ ]:
#Accessing an index which does not exist generates an exception (an error).

, mylist = [1,2,3]
print(mylist[10])



5- Basic Operators
This section explains how to use basic operators in Python.

5.1- Arithmetic Operators
Just as any other programming languages, the addition, subtraction, multiplication, and
division operators can be used with numbers.
In [ ]:
number = 1 + 2 * .0
print(number)
2.5
In [ ]:
print(type(number))
In [ ]:
# Another operator available is the modulo (%) operator, which returns the
integer remainder of the division. dividend % divisor = remainder
remainder = 11 % 3
print(remainder)
2
In [ ]:
# Using two multiplication symbols makes a power relationship.
squared = 7 ** 2
cubed = 2 ** 3
print(squared)
print(cubed)

5.2 -Using Operators with Strings
Python supports concatenating strings using the addition operator:
In [ ]:
helloworld = "hello" + " " + "world"
print(helloworld)
hello world
In [ ]:
lotsofhellos = "hello" * 10
print(lotsofhellos)
hellohellohellohellohellohellohellohellohellohello

Document information

Uploaded on
January 11, 2025
Number of pages
68
Written in
2024/2025
Type
Class notes
Professor(s)
David j. malan
Contains
All classes
$8.77

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
0
Followers
0
Items
1
Last sold
-



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions