0% found this document useful (0 votes)
17 views4 pages

Session 2

The document provides an introduction to Python including basics like variables, strings, lists, tuples, dictionaries, sets, arithmetic operations, taking user input, and string methods. It shows many code examples to demonstrate Python concepts.

Uploaded by

darayir140
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

Session 2

The document provides an introduction to Python including basics like variables, strings, lists, tuples, dictionaries, sets, arithmetic operations, taking user input, and string methods. It shows many code examples to demonstrate Python concepts.

Uploaded by

darayir140
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

15/05/2021 Python Crash Course.

ipynb - Colaboratory

Python Crash Course

Basics
First Program
Arithmetic Operation
Variables
Strings
Comments
List
Tuple
Dictionary
Set

The Very First Program

print("Hello World! we are going to dive in Python")


Hello World! we are going to dive in Python

print('HI this is Vishwas \n book')

HI this is Vishwas
book

You can use it as Calculator

Arithmatic Operation
5+5 = 10

5+17834

17839

5/2

2.5

1435//4
https://colab.research.google.com/drive/14imixDGR-Y7pS2OnNRLUrPiVREKCpkiu#scrollTo=rUtC01FuNSVx&printMode=true 1/9
15/05/2021 Python Crash Course.ipynb - Colaboratory

358

2**4
16

Variables
Variables are the names you give to computer
memory locations which are used to store values
in a computer program.

message = "Data Science for Beginners"


print(message)

Data Science for Beginners

message = "Python is Great!"


print(message)

Python is Great!

message = "Hello Python Crash Course reader!"


print(message)
Hello Python Crash Course reader!

a = 2
b = 3
sum = a+b
print(sum)
5

a = '34.5'
print(type(a))
<class 'str'>

Taking input from users


The input() function pauses your program
and waits for the user to enter some text.

https://colab.research.google.com/drive/14imixDGR-Y7pS2OnNRLUrPiVREKCpkiu#scrollTo=rUtC01FuNSVx&printMode=true 2/9
15/05/2021 Python Crash Course.ipynb - Colaboratory

message = input("Enter any message: ")


print(message)
print(type(message))
Enter any message: hi
hi
<class 'str'>

age = input("How old are you? ")


print("My age is: ", age)
How old are you? 23
My age is: 23

age = input("How old are you? ")


age > 18

How old are you? 34


---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-15-4850b80743eb> in <module>()
1 age = input("How old are you? ")
----> 2 age > 18

TypeError: '>' not supported between instances of 'str' and 'int'

SEARCH STACK OVERFLOW

age = int(input("How old are you? "))


age >= 18

How old are you? 24


True

x = input("Enter a number: ")


y = x + 5
print(y)

Enter a number: 7
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-17-562e36f0664a> in <module>()
1 x = input("Enter a number: ")
----> 2 y = x + 5
3 print(y)

TypeError: can only concatenate str (not "int") to str

SEARCH STACK OVERFLOW

https://colab.research.google.com/drive/14imixDGR-Y7pS2OnNRLUrPiVREKCpkiu#scrollTo=rUtC01FuNSVx&printMode=true 3/9
15/05/2021 Python Crash Course.ipynb - Colaboratory

print(type(x))
<class 'str'>

x = input("Enter a number: ")


y = x + "5"
print(y)
Enter a number: 8
85

x = int(input("Enter a number: "))


y = x + 5
print(y)

Enter a number: 3
8

message = "Hello Python Crash Course reader!"


print(mesage)

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-21-c8f2adeaed02> in <module>()
1 message = "Hello Python Crash Course reader!"
----> 2 print(mesage)

NameError: name 'mesage' is not defined

SEARCH STACK OVERFLOW

String
A string is simply a series of characters.
Anything inside quotes is considered a string in Python,
and you can use single or double quotes around your strings like this:

"This is a string."
'This is also a string.'

name = "data science"


print(name)

name = "data science"


print(name.title())

https://colab.research.google.com/drive/14imixDGR-Y7pS2OnNRLUrPiVREKCpkiu#scrollTo=rUtC01FuNSVx&printMode=true 4/9

You might also like