---
# System prepended metadata

title: 'Date Types, Variables and I/O'

---

---
title: Python-1 Module Introduction
description: 
duration: 900
card_type: cue_card
---

# Python-1 Module Introduction 

<span style="background-color: pink;">**Ice-breaking**</span> 

Hey Everyone, welcome to your first session of the Python-1 module.

I hope you have a great time learning and interacting here. To get to know each other better, let's start with a quick introduction! Please share two lines about yourself in the chat.

Alright, to begin, let me introduce myself. My name is [Your Name], and [brief introduction about yourself and experience]. <font color='red'>**Display & Share your LinkedIn profile with the learners.**</font>

I'm here to guide you on your learning journey at Scaler. I'll be closely monitoring your progress, and if I see any areas needing improvement, I'll reach out to you to understand the challenges.

However, remember, open communication is key! Don't hesitate to reach out (via Slack/WhatsApp DM) if anything troubles you, big or small. We're here to support you and help you succeed! Let's work together to avoid any dips in your performance.

Now that we've gotten to know each other a bit, let's dive into the Python-1 module!

### <font color='purple'>**Module Importance**</font>

* Python is a popular and widely used programming language, known for its simplicity.
* Specifically in the domains of Data Science and Machine Learning, Python emerges as the go-to language.
* In this module, you'll learn the fundamentals & core concepts of Python.
* You will understand how Python is different from other languages, focusing on the task rather than complex syntaxes.
* This module serves as a base, preparing you for the advanced Python concepts covered in the subsequent Python-2 module.

#### <font color='red'>**Instructor Note:**</font>
       
- Perform a brief Google search on essential skills for data analysts/scientists, emphasizing the importance of Python. 
- Highlight that mastering Python will benefit the learner in other related modules as well, such as DAV, ML, NLP, CV.

**Example JDs:**

<img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/066/753/original/Screen_Shot_2024-02-29_at_15.41.35_PM.png?1709201774" width="600" height="800">

### <font color='purple'>**Module Overview**</font>

Below, you’ll find a comprehensive breakdown of the lectures:

<img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/067/407/original/Python-1_flowchart.png?1709747547" width="600" height="450">

At the end of this module, there will be a <font color='red'>**MODULE TEST**</font> designed to evaluate and solidify your acquired skills.

### <font color='purple'>Module Expectation</font>

* This module is carefully crafted to ensure a strong hold on the fundamentals of Python.
* It's crucial to note that while this course lays a solid foundation in Python, it doesn't make you a Python Developer upon completion.
* To become proficient in Python, we encourage you to continue your learning through the next module of Python-2 focussing on the advanced concepts.
* Python is a powerful programming language with endless possibilities, and there's always more to discover beyond the scope of this course.
* It is recommended to do regular problem-solving exercises to become a Python expert.

### <font color='purple'>Attendance</font>

* Try to maintain at least **75% attendance** either through live classes or by watching recordings.
* However, I recommend you attend classes regularly because otherwise, it may create backlogs.
* So, I expect all of you to attend live classes and if you are unable to, please send me a message stating the reason.

### <font color='purple'>Assessments & PSP</font>

This module covers every from fundamental Python concept spread across 11 comprehensive lectures.

Sharpen your skills with solving assessments:
- **5 assignment questions** per lecture
- **3-5 homework questions** per lecture (optional)

**Aim for a high PSP score (85+):**
- **PSP (Problem Solving Percentage)** - Solved Assignment Problems / Total Open Assignment Problems
- Demonstrates your expertise in fundamental Python, a valuable asset for your resume and interviews.
- Not just for academic success, but it prepares you for real-world applications as well.

We'd like to clarify that your **PSP is calculated solely based on your performance on assignment problems**. Homework problems do not contribute to your PSP. 

However, once you're done with the assignments, we strongly recommend completing the homework for further practice. 

**Remember:**
- Seek help: Reach out to instructors or TAs for guidance.
- Track progress: Monitor PSP scores and adjust learning strategies accordingly.

### <font color='purple'>Post-lecture Content
</font>

- We encourage you to regularly access **post-lecture content** via the dashboard.
- You’ll receive a comprehensive **cheat sheet** as well at the end of the module.

#### <font color='red'>Ready to master Python fundamentals? Let's get started!</font>

---
title: Agenda
description:
duration: 300
card_type: cue_card
---

# Date Types, Variables and I/O

### Agenda

* Motivation behind programming languages
* Getting Started with Python
* Print Statement
* Data Types
    * Integer
    * Float
    * String
    * Bool
    * NoneType
* `type()`
* Variables
* I/O - `input()`
    * `int()`
    * `str()`
    
---
title: Setup & Print Statement
description:
duration: 1800
card_type: cue_card
---

## Motivation behind programming languages -

#### Can you talk to a computer in English?
- Computer only understands electric signal - '**High**' and '**Low**'.
- The language understood by computer is called binary language with **0/1** where '1' is high and '0' is low.

</br>

1. **Translator** - A computer program, is needed to convert human -understandable language to binary language.
2. **Human** - Understandable language is called 'High level language'.
  e.g. Python, Java, Javascript, Ruby, etc.
3. **Syntax** - Set of rules or grammar for writing a computer program.

## Getting Started with Python 

1.  Python Insallation (<https://www.python.org/downloads/>)
2.  Editor (.py)
3.  CMD (execute)

Instead, let's use an **IDE**.

IDE - Integrated Development Environment

Example:
-   VS Code
-   Pycharm
-   Online IDE

Introducing online IDEs
-   ide.view
-   ide.codingminutes
-   `Google Colab` 

## **Print Statement**

Code
```python=
print(3000)
```

> Output

    3000
    
Code
```python=
print(20+30) # python does basic arithmetic operations
```

> Output

    50
    
Code
```python=
print(4 + 9) # spaces in middle don't matter
```

> Output

    13

Code
```python=
# everything inside " " printed as it is
print("I love you all 3000!")
```

> Output

    I love you all 3000!

Code
```python=
# will give an error without the quotes
print(I love you all 3000!)
```

**Note:**
Python is case sensitive.
-   `Print` is invalid
-   `print` is valid

---
title: Quiz-1
description: Quiz-1
duration: 60
card_type: quiz_card
---

# Question

Predict the output of the following.

```python=
print(8-5)
```

# Choices

- [ ] 8-5
- [x] 3
- [ ] Error

---
title: Data Types
description:
duration: 1200
card_type: cue_card
---

## **Data Types**

-   The type of data that we are dealing with.
-   e.g. **Text**, **Numbers**, **Decimals**, etc.

### **Int (Integers)**

-   A data type that deals with **positive** or **negative** whole numbers. 
-   e.g. 1, -4, 8, 0, 323434242...
-   Python has no upper limit on size.

### **Float (Decimals)**

- All real numbers that are not Integers. 
- e.g. .3, 0.123, -2.4

\
**Question**: Is **9** and **9.0** same? 
- In real sense they are same, 
- But in Python they're **different**.
    - 9.0 is a **float**  
    - 9 is an **integer**

**Note:** '.' is not a decimal but '0.' is

### **Strings**

- Anything inside quotes is considered string.
- We can use either Double quotes (" ") or Single quotes (' ').
- We have to start and end with the same type of quote.

**Example**:
- `"Hello everyone"` - **valid**
- `'hello'` - **valid**
- `"hey everyone'` - **invalid**

### **Bool (boolean)**

-   It has a `True` or `False` value.
-   `True` is usualy 'high' and `False` is 'low'.
-   We use boolean values when comparing.

Code
```python=
print(2 > 3)
```

> Output
        
        False

### **None** Type

-   Has only one value, `None`.
-   Used to represent nothing or an empty value.

---
title: Quiz-2
description: Quiz-2
duration: 60
card_type: quiz_card
---

# Question

Which of the following values are of type **float** in Python?

# Choices

- [x] .2
- [ ] "2.3"
- [ ] '3.14'
- [ ] -3

---
title: Checking the data types of objects
description:
duration: 900
card_type: cue_card
---

#### **How do you check data type of a given object?**

Every value inside python is called an object. 

**Ans**: Using the `type()` function

### `type()`

-   It takes in an object and returns the data type of the object.


Code
```python=
type("hello") 
```

> Output

    str

Code
```python=
type(45)
```

> Output

    int

Code
```python=
type(67.8)
```

> Output

    float

Code
```python=
type(True)
```

> Output

    bool

Code
```python=
type(None)
```

> Output

    NoneType

**Note:**
-   IDE or a Python Shell might not print the result from `type()`.
-   But Jupyter or Colab notebook prints the result of `type()` by default.

Code
```python=
print(type("hello"))
```

> Output

    <class 'str'>

-   The result of `type()` function is passed to the `print()` function and the output is printed on the screen, in both IDE and Jupyter/Colab notebook.

<img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/059/778/original/download_%283%29.png?1703074010">

---
title: Break & Doubt Resolution
description:
duration: 600
card_type: cue_card
---

### Break & Doubt Resolution

`Instructor Note:`
* Kindly take this time (up to 5-10 mins) to give a short break to the learners.
* Meanwhile, you can ask the them to share their doubts (if any) regarding the topics covered so far.

---
title: Introduction to Variables
description:
duration: 1200
card_type: cue_card
---

## **Variables**

-   Variables are nothing but containers to keep objects.
-   A variable is an identifier / name given to an object.
-   A variable in python refers to a reserved memory location.

Code
```python=
a = 3
print(a) 
```

> Output

    3

Code
```python=
b = 4
a + b 
```

> Output

    7

-   Python does not need specification about what data it stores.
-   It automatically knows the type based on what it stores.

Code
```python=
type(a)
```

> Output

    int

-   In Python, the code is read from top to bottom.
-   The values in a variable can be changed.

Code
```python=
x= 3
x= 5
print(x) 
```

> Output

    5

Code
```python=
x = "i am"
y = "legend !"
print(x)
print(y) # prints in seperate lines
```

> Output

    i am
    legend !

Code
```python=
print(x, y) # prints space seperated
```

> Output

    i am legend !

---
title: Naming variables
description:
duration: 600
card_type: cue_card
---

## **Variable naming rules -**

A Python identifier can be a combination of lowercase/ uppercase letters, digits, or an underscore. 

The following characters are valid:
-   Lowercase letters (a to z)
-   Uppercase letters (A to Z)
-   Digits (0 to 9)
-   Underscore (\_)

**Example:**
-   video_1
-   myVar

**Note:**
- An identifier cannot begin with a digit. 
- Example: `1video` is **invalid**.


Code
```python=
x = 10
y = x
print(y)
```

> Output

    10

<img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/059/779/original/download_%284%29.png?1703074200">

<img src="https://d2beiqkhq929f0.cloudfront.net/public_assets/assets/000/059/780/original/download_%285%29.png?1703074271">

---
title: Quiz-3
description: Quiz-3
duration: 60
card_type: quiz_card
---

# Question

Which of the following is a valid variable name?

# Choices

- [x] `hELLO`
- [ ] `1_name_Input`
- [ ] `a*b*c`
- [ ] `Cod3$#`

---
title: Taking Input
description:
duration: 900
card_type: cue_card
---

## **Taking inputs from user -**


The `input()` function takes in an input provided by the user.

Code
```python=
name = input()
name
```

> Input 

    Bipin
    
> Output

    'Bipin'

Code
```python=
name = input()
print("hello name") # name is a string
```

> Input

    Bipin
    
> Output
    
    hello name

Code
```python=
name=input()
print("hello", name) # name is a variable
```

> Input

    Bipin
    
> Output
    
    hello Bipin

---
title: Quiz-4
description: Quiz-4
duration: 60
card_type: quiz_card
---

# Question

Predict the output of the following.

```python=
x = 3
y = 'hello'
num = y
y = 5
print(num, y)
```

# Choices

- [ ] `5 5`
- [ ] `hello hello`
- [x] `hello 5`

---
title: Taking input as integer / string
description:
duration: 900
card_type: cue_card
---

### **Question:** Write a program to take two numbers as input and add them.

Code
```python=
x = input() 
y = input() 
print(x+y) # input taken as string #4554
```

> Input 

    45
    54
    
> Output
    
    4554

- The `input()` functions takes input as a string.
- The `int()` function converts the input into an integer.

Code
```python=
x = input()
y = input()
int_x = int(x)
int_y = int(y)
print(type(int_x)) 
print(type(int_y)) 
```

> Input

    45
    54
    
> Output

    <class 'int'>
    <class 'int'>

Code
```python=
x = "I am a string"
int(x) # error, this string cannot be converted to integer
```

> Output

    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    <ipython-input-25-6884c7679f60> in <module>
          1 x = "I am a string"
    ----> 2 int(x) #error, this string cannot be converted to integer

    ValueError: invalid literal for int() with base 10: 'I am a string'

-   The `str()` function converts an input into a string.

Code
```python=
x = 345
str(x) 
```

> Output

    '345' 
    
#### <span style="color: red;">**Instructor Note:**</span> 

Share these instructions and ref video link with the learners.

Instructions to access the post-lecture notes : 
1. Click on the **.ipynb file** available on your dashboard.
2. When a webpage with the markdown opens, **Right Click** and **Save As**.
3. Save the file onto your local system with an **.ipynb extension**.
4. Try opening the file via **Jupyter Notebook** or **Google Colab**.

**Reference Video -** [**link**](https://www.loom.com/share/299766495f264f9798eef43e024e6d66?sid=d4cc00e7-df53-4428-992c-4124130a5b8e)


---
title: Practice Coding Question(s)
description: 
duration: 600
card_type: cue_card
---

### Practice Coding Question(s)

You can pick the following question and solve it during the lecture itself.

This will help the learners to get familiar with the problem solving process and motivate them to solve the assignments.

<span style="background-color: pink;">Make sure to start the doubt session before you start solving the question.</span>

Q. https://www.scaler.com/hire/test/problem/96775/
