From 7391354522c8e1e109069489df8acef4143a60a0 Mon Sep 17 00:00:00 2001 From: kritarth2135 Date: Wed, 26 Aug 2026 21:33:48 +0530 Subject: [PATCH 1/6] Added chapter 4 of python tutorial --- .../chapters/04-built-in-functions-pt-1.md | 113 ++++++++++++++++++ docs/python-tutorial/chapters/index.md | 2 +- zensical.toml | 1 + 3 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 docs/python-tutorial/chapters/04-built-in-functions-pt-1.md diff --git a/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md b/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md new file mode 100644 index 0000000..4b417e3 --- /dev/null +++ b/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md @@ -0,0 +1,113 @@ +--- +description: Built-in Functions Part 1 +--- + +# Built-in Funcitons Part 1 + +!!! note + + This chapter will only cover how to use some built-in functions so for now consider functions as + helper code which does some specific task and is pre-written for you to use. You will learn about + functions in great detail later in this tutorial so don't worry about that for now. + +Python has many built-in functions which you can use to make your life easier. In this section we will +take a look at `print`, `input` and some type casting functions in detail. + +## `print()` + +`print` function is used to print / show something on the screen also known as the terminal or standard +output. With this you can write the first program that every programmer writes when they learn a new +language: + +```python +print("Hello World!") # Output: Hello World! +``` + +This line of code will print `Hello World!` on your screen. You can also print any datatype (`int`, +`float`, `string`) using `print`. + +```python +print("My name is Alex") # Output: My name is Alex +print(56) # Output: 56 +print(3.14) # Output: 3.14 +print(False) # Output: False +``` + +You can also print the data currently present in a variable using `print`. + +```python +a = 5 +print(a) # Output: 5 +a = "python" +print(a) # Output: python +``` + +Each `print` statement prints on a new line. You can print multiple things using a single `print` +statement by separating them using `,`s which will result in all the values being printed on the +same line separated by spaces. + +```python +print("Value of pi is", 3.14) # Output: Value of pi is 3.14 +``` + +!!! note + + Keep in mind that this works only in `print` and can NOT be used to combine different strings + or variables with strings otherwise. + +## `input()` + +`input` function is used to take input from the user through the terminal also known as the standard +input. It returns everything the user types until the user hits `Enter` on the keyboard. You can also +give a `string` to the `input` function which will be displayed on the screen while taking the input. +For example: + +```python +input("Enter your name: ") +``` + +The above code will print `Enter your name: ` followed by a blinking cursor where you can type the +actual input. Now to actually use the value the user entered you need to assign the value returned +by the `input` function to a variable. + +```python +name = input("Enter your name: ") +print(name) +``` + +The `input` function returns the input as a `string` so the variable `name` will be of type `string`. +The output of above code will be whatever the user entered. + +## Type Casting + +Now you know how to take input from the user, but, the `input` function returns a `string` no matter +what the user types. So for example if the user types `54`, it will return a `string` (`"54"`) not an +`int` (`54`). So if you want to use the number the user entered, you will need to convert the `string` +returned by `input` to an `int`. This process of converting one data type to another is called **type +casting**. + +There are two types of type casting: + +1. **Implicit Type Casting**: It is done automatically by `python` when it is needed. +2. **Explicit Type Casting**: It is done manually by the programmer. + +### Explicit Type Casting + +Python has many built-in functions for explicit type casting and they are often named the same as the +data type it casts to. Here is the list of type casting functions with the type it casts to: + +| Function | Type | +|-----------|------| +| `bool()` | `bool` | +| `float()` | `float` | +| `int()` | `int` | +| `str()` | `string` | + +For example to get a number from the user you can do: + +```python +number_string = input("Enter a number: ") +number_int = int(number_string) +``` + +Similarly you can use other functions according to the data type you need. diff --git a/docs/python-tutorial/chapters/index.md b/docs/python-tutorial/chapters/index.md index 6088bb4..ba53914 100644 --- a/docs/python-tutorial/chapters/index.md +++ b/docs/python-tutorial/chapters/index.md @@ -9,7 +9,7 @@ description: List of topics to be covered in the Python tutorial. - [Brief Python History](01-python-history.md) - [Introduction to Variables](02-intro-to-variables.md) - Data Types pt 1 (`int`, `float`, `bool` & `strings`) -- Builtin Functions pt 1 (`print` & `input` and type casting) +- [Builtin Functions pt 1 (`print` & `input` and type casting)](04-built-in-functions-pt-1.md) - String Interpolation & Concatenation (f-strings, str.format & +) - Operators pt 1 (Comparison & Arithmetic) - Conditional Statements (`if`, `else` & `elif`) diff --git a/zensical.toml b/zensical.toml index c239086..d3e3ad7 100644 --- a/zensical.toml +++ b/zensical.toml @@ -23,6 +23,7 @@ nav = [ "python-tutorial/chapters/index.md", "python-tutorial/chapters/01-python-history.md", "python-tutorial/chapters/02-intro-to-variables.md", + "python-tutorial/chapters/04-built-in-functions-pt-1.md", ] }, { "Resources" = [ "resources/index.md", From 56b0c490766bb991c05dde9e53630a2cc3d3537e Mon Sep 17 00:00:00 2001 From: kritarth2135 Date: Sat, 29 Aug 2026 17:55:09 +0530 Subject: [PATCH 2/6] Fixed grammatical errors, typos, confusing wordings --- .../chapters/04-built-in-functions-pt-1.md | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md b/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md index 4b417e3..3fb11a9 100644 --- a/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md +++ b/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md @@ -2,29 +2,29 @@ description: Built-in Functions Part 1 --- -# Built-in Funcitons Part 1 +# Built-in Functions Part 1 !!! note - This chapter will only cover how to use some built-in functions so for now consider functions as + This chapter will only cover how to use some built-in functions. So, for now, consider functions as helper code which does some specific task and is pre-written for you to use. You will learn about - functions in great detail later in this tutorial so don't worry about that for now. + functions in great detail later in this tutorial, so don't worry about that for now. -Python has many built-in functions which you can use to make your life easier. In this section we will -take a look at `print`, `input` and some type casting functions in detail. +Python has many built-in functions which you can use to make your life easier. In this section, we +will take a look at `print`, `input`, and some type-casting functions in detail. ## `print()` -`print` function is used to print / show something on the screen also known as the terminal or standard -output. With this you can write the first program that every programmer writes when they learn a new -language: +The `print` function is used to print/show something on the screen (also known as the terminal or +standard output). With this you can write the first program that every programmer writes when they +learn a new language: ```python print("Hello World!") # Output: Hello World! ``` -This line of code will print `Hello World!` on your screen. You can also print any datatype (`int`, -`float`, `string`) using `print`. +This line of code will print `Hello World!` on your screen. You can also print any other data type +(such as `int`, `float`, or `bool`) using `print`. ```python print("My name is Alex") # Output: My name is Alex @@ -43,8 +43,8 @@ print(a) # Output: python ``` Each `print` statement prints on a new line. You can print multiple things using a single `print` -statement by separating them using `,`s which will result in all the values being printed on the -same line separated by spaces. +statement by separating them using commas(`,`), which will result in all the values being printed on +the same line separated by spaces. ```python print("Value of pi is", 3.14) # Output: Value of pi is 3.14 @@ -52,22 +52,22 @@ print("Value of pi is", 3.14) # Output: Value of pi is 3.14 !!! note - Keep in mind that this works only in `print` and can NOT be used to combine different strings - or variables with strings otherwise. + Keep in mind that this works only in `print` and can NOT be used to combine different strings or + variables with strings otherwise. ## `input()` -`input` function is used to take input from the user through the terminal also known as the standard -input. It returns everything the user types until the user hits `Enter` on the keyboard. You can also -give a `string` to the `input` function which will be displayed on the screen while taking the input. -For example: +The `input` function is used to take input from the user through the terminal (also known as the +standard input). It returns everything the user types until the user hits the `Enter`/ `Return` key +on the keyboard. You can also give a `str` to the `input` function which will be displayed on the +screen while taking the input. For example: ```python input("Enter your name: ") ``` The above code will print `Enter your name: ` followed by a blinking cursor where you can type the -actual input. Now to actually use the value the user entered you need to assign the value returned +actual input. Now, to actually use the value the user entered, you need to assign the value returned by the `input` function to a variable. ```python @@ -75,25 +75,25 @@ name = input("Enter your name: ") print(name) ``` -The `input` function returns the input as a `string` so the variable `name` will be of type `string`. -The output of above code will be whatever the user entered. +The `input` function returns the input as a `str` so the variable `name` will be of type `str`. The +output of above code will be whatever the user entered. ## Type Casting -Now you know how to take input from the user, but, the `input` function returns a `string` no matter -what the user types. So for example if the user types `54`, it will return a `string` (`"54"`) not an -`int` (`54`). So if you want to use the number the user entered, you will need to convert the `string` -returned by `input` to an `int`. This process of converting one data type to another is called **type -casting**. +Now you know how to take input from the user, but, the `input` function returns a `str` no matter +what the user types. So, for example, if the user types `54`, it will return a `str` (`"54"`), not +an `int` (`54`). So if you want to use the number the user entered, you will need to convert the +`str` returned by `input` to an `int`. This process of converting one data type to another is called +**type casting**. There are two types of type casting: -1. **Implicit Type Casting**: It is done automatically by `python` when it is needed. +1. **Implicit Type Casting**: It is done automatically by Python when it is needed. 2. **Explicit Type Casting**: It is done manually by the programmer. ### Explicit Type Casting -Python has many built-in functions for explicit type casting and they are often named the same as the +Python has many built-in functions for explicit type casting, and they are named the same as the data type it casts to. Here is the list of type casting functions with the type it casts to: | Function | Type | @@ -101,13 +101,13 @@ data type it casts to. Here is the list of type casting functions with the type | `bool()` | `bool` | | `float()` | `float` | | `int()` | `int` | -| `str()` | `string` | +| `str()` | `str` | -For example to get a number from the user you can do: +For example, to get a number from the user you can do this: ```python number_string = input("Enter a number: ") number_int = int(number_string) ``` -Similarly you can use other functions according to the data type you need. +Similarly, you can use other functions according to the data type you need. From 7e11ebdf4030479b501e8798f4dd81fca875077e Mon Sep 17 00:00:00 2001 From: kritarth2135 Date: Sat, 29 Aug 2026 17:58:52 +0530 Subject: [PATCH 3/6] Oops, forgot a hyphen --- docs/python-tutorial/chapters/04-built-in-functions-pt-1.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md b/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md index 3fb11a9..6bfa128 100644 --- a/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md +++ b/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md @@ -94,7 +94,7 @@ There are two types of type casting: ### Explicit Type Casting Python has many built-in functions for explicit type casting, and they are named the same as the -data type it casts to. Here is the list of type casting functions with the type it casts to: +data type it casts to. Here is the list of type-casting functions with the type it casts to: | Function | Type | |-----------|------| From 9a6f4d7d936dc5c99979a2ff368904bcb0d8adbb Mon Sep 17 00:00:00 2001 From: kritarth2135 Date: Sat, 29 Aug 2026 18:03:15 +0530 Subject: [PATCH 4/6] Another one --- docs/python-tutorial/chapters/04-built-in-functions-pt-1.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md b/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md index 6bfa128..cdde663 100644 --- a/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md +++ b/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md @@ -94,7 +94,7 @@ There are two types of type casting: ### Explicit Type Casting Python has many built-in functions for explicit type casting, and they are named the same as the -data type it casts to. Here is the list of type-casting functions with the type it casts to: +data type it casts to. Here is the list of type-casting functions with the type they cast to: | Function | Type | |-----------|------| From f217b3b960ea15468db0b318a9c6fda7d87b9bd4 Mon Sep 17 00:00:00 2001 From: kritarth2135 Date: Mon, 31 Aug 2026 22:01:11 +0530 Subject: [PATCH 5/6] Missed some commas, round 2 --- .../chapters/04-built-in-functions-pt-1.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md b/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md index cdde663..b8815c3 100644 --- a/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md +++ b/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md @@ -16,7 +16,7 @@ will take a look at `print`, `input`, and some type-casting functions in detail. ## `print()` The `print` function is used to print/show something on the screen (also known as the terminal or -standard output). With this you can write the first program that every programmer writes when they +standard output). With this, you can write the first program that every programmer writes when they learn a new language: ```python @@ -43,8 +43,8 @@ print(a) # Output: python ``` Each `print` statement prints on a new line. You can print multiple things using a single `print` -statement by separating them using commas(`,`), which will result in all the values being printed on -the same line separated by spaces. +statement by separating them using commas (`,`), which will result in all the values being printed +on the same line separated by spaces. ```python print("Value of pi is", 3.14) # Output: Value of pi is 3.14 @@ -52,7 +52,7 @@ print("Value of pi is", 3.14) # Output: Value of pi is 3.14 !!! note - Keep in mind that this works only in `print` and can NOT be used to combine different strings or + Keep in mind that this works only in `print` and CANNOT be used to combine different strings or variables with strings otherwise. ## `input()` @@ -82,7 +82,7 @@ output of above code will be whatever the user entered. Now you know how to take input from the user, but, the `input` function returns a `str` no matter what the user types. So, for example, if the user types `54`, it will return a `str` (`"54"`), not -an `int` (`54`). So if you want to use the number the user entered, you will need to convert the +an `int` (`54`). So, if you want to use the number the user entered, you will need to convert the `str` returned by `input` to an `int`. This process of converting one data type to another is called **type casting**. @@ -94,7 +94,7 @@ There are two types of type casting: ### Explicit Type Casting Python has many built-in functions for explicit type casting, and they are named the same as the -data type it casts to. Here is the list of type-casting functions with the type they cast to: +data type they cast to. Here is the list of type-casting functions with the type they cast to: | Function | Type | |-----------|------| @@ -103,7 +103,7 @@ data type it casts to. Here is the list of type-casting functions with the type | `int()` | `int` | | `str()` | `str` | -For example, to get a number from the user you can do this: +For example, you can do this to get a number from the user: ```python number_string = input("Enter a number: ") From 26689afac3df23b376dc446899de062d6e4b6c2b Mon Sep 17 00:00:00 2001 From: kritarth2135 Date: Mon, 31 Aug 2026 22:12:12 +0530 Subject: [PATCH 6/6] Missed some commas, round 3 --- docs/python-tutorial/chapters/04-built-in-functions-pt-1.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md b/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md index b8815c3..22578d3 100644 --- a/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md +++ b/docs/python-tutorial/chapters/04-built-in-functions-pt-1.md @@ -11,7 +11,7 @@ description: Built-in Functions Part 1 functions in great detail later in this tutorial, so don't worry about that for now. Python has many built-in functions which you can use to make your life easier. In this section, we -will take a look at `print`, `input`, and some type-casting functions in detail. +will take a look at `print`, `input` and some type-casting functions in detail. ## `print()` @@ -75,7 +75,7 @@ name = input("Enter your name: ") print(name) ``` -The `input` function returns the input as a `str` so the variable `name` will be of type `str`. The +The `input` function returns the input as a `str`, so the variable `name` will be of type `str`. The output of above code will be whatever the user entered. ## Type Casting