Python Tutorial for Beginners

 

#0 Python for Beginners | Programming Tutorial

Learn Python Programming in a Fun and Fast Way with Disco Learnings


Are you interested in learning programming, specifically Python, in an entertaining and efficient manner? Look no further than Disco Learnings! and in this series, you will gain a solid understanding of the Python language from start to finish. The only prerequisite is your time; even if you have never programmed before, that is completely fine because we will start from scratch. You will learn the language fundamentals, syntax, and concepts in an engaging and memorable way. Best of all, this Python series is freely available, so you can learn at your own pace without any cost.

If learning online is not your thing, you may get bored or distracted, but in this series, I will do my best to make the sessions as interesting as possible. I may use my presence, animations, and other tools to keep you engaged and focused. I hope you enjoy this series, but before you get started, make sure to subscribe to my channel and share it with your friends. Let's make programming accessible to everyone! Have a Welcome !

#1 Python Tutorial for Beginners | Introduction to Python

Introduction to Python

Welcome back, and we are starting a series on Python. Python is one of the fastest growing languages in terms of the number of developers who are using it, the number of libraries available, the number of companies using it, and the areas in which it can be implemented. It's called a general-purpose language and can be used in machine learning, GUI software development, web development, and more.

we will discuss what Python is, why it's useful, and why you should learn it. Python is an interpreted, object-oriented, and high-level programming language that also supports procedural programming. It's been around since 1989, before Java. Despite the popularity of other languages like C, C++, Java, and JavaScript, Python is still famous and widely used. Python has become the language of choice for research scientists working in the fields of machine learning and AI since it's easier to learn than other languages.

Python is easier to learn compared to other languages, such as C, C++, and Java. Most colleges and schools teach Python, and even children can learn it. Python has multiple versions, including 1.x, 2.x, and 3.x. We should learn 3.x since it's the newest version.

Why is Python So Famous?

Python is famous because it's easy to learn and implement. It's used by many big companies, including Google, YouTube, and Dropbox, and is the main language or a support language for many. The author of Python was a big fan of a British comedy movie called Monty Python's Flying Circus, and that's why he named it Python.

Conclusion

Python is an easy-to-learn, general-purpose language that can be used in various fields. In the next video, we will discuss how to install Python and work with different features. I hope you enjoy this series, and let me know in the comments if you have any questions or suggestions. Thanks for watching!

#2 Python Tutorial for Beginners | Python Installation | PyCharm

Introduction to Python and IDEs

If you want to write code in Python, you need to have an editor. You can use an editor like Notepad, Notepad++, Atom, or Sublime, among others. Python can be used for machine learning, AI, software development, or simple math operations like adding two numbers.

To get started, you need to install a Python interpreter, which can be downloaded from the official website or other setups. In some cases, the interpreter may already be installed on your computer by default.

One of the best IDEs for writing Python code is PyCharm, which is free to use. To install Python, go to the official website, download the setup, and follow the installation instructions. Once you have installed Python, you can start using it in your IDE.

PyCharm provides you with amazing features, but there are other IDEs available in the market as well. To use Python, you need to understand how it works and how to use the interpreter.

Verifying Python Installation

To verify that Python is installed on your computer, you can go to your Windows and search for Python. If you have installed Python successfully, you will see Python 3.7 or the latest version installed.

Using PyCharm

PyCharm is one of the best IDEs for Python with many features. To use PyCharm, you need to download and install it from the official website. PyCharm is available in both the professional and community versions. The community version is free to use, while the professional version is available for a price.

To use the community version, click on the download button and follow the instructions. To use the professional version, click on the professional version and follow the instructions.

Conclusion

Python is a powerful language that can be used for many purposes, and PyCharm is one of the best IDEs for Python. To get started, download and install Python and an IDE like PyCharm. You can then start writing and executing Python code for your projects.

PyCharm can be set up for specific types or extensions. It takes a few minutes to install and can be used for writing Python code and creating new projects. There are both light and dark themes available, but for content creation, the white theme is preferred for YouTube videos. After selecting the white theme, click "Next" and deselect any unnecessary features before clicking "Start using PyCharm." Don't forget to like the video before leaving!

If you have any further questions or issues with the installation, feel free to leave a comment and other members of the community may be able to help you out. Thanks for watching and see you in the next episode of PyCharm!

  • Set up PyCharm for specific types or extensions
  • Install takes a few minutes
  • Can be used for writing Python code and creating new projects
  • White theme is preferred for YouTube videos
  • Deselect unnecessary features before starting to use PyCharm


  • #3 Python Tutorial for Beginners | Getting Started with Python

    • Welcome back.....

    • . Now, it's time to dive into the actual coding.

    Step 1: Opening Your IDE

    • Before we start with the actual code, we have to ask ourselves, why do we code? We live in a world where everything is done with computers. If we want to talk to our computer, we need to understand their language, which is binary code. However, it's not exactly possible to talk to a computer in binary code. So, we created programming languages, like Python, to bridge the gap between human and computer languages.

      To start coding in Python, we need to open our Integrated Development Environment (IDE). In this tutorial, we will be using IDLE, which is one of the easiest IDEs to use.

    Basic Operations in Python

    • Let's start with some basic operations. We will be using the Python interpreter to execute our code. We will try out addition, subtraction, multiplication, and division.

      • Addition: To add two numbers, we use the '+' symbol. For example, 2+3=5.
      • Subtraction: To subtract two numbers, we use the '-' symbol. For example, 9-8=1.
      • Multiplication: To multiply two numbers, we use the '*' symbol. For example, 4*6=24.
      • Division: To divide two numbers, we use the '/' symbol. For example, 8/4=2.0. Note that this gives us a float value.

      We can also use brackets to group our operations. For example, (8+9)-10=7.

      We can also use exponentiation to find the power of a number. To do this, we use the double asterisk '**' symbol. For example, 2**3=8.

    Python Fundamentals

    • In Python, we can perform various operations like flow division and modulus. For example, when we divide 10 by 3, we get the result as 3 with a remainder of 1 (10%3). We can also use strings in Python, which are a combination of characters like "naveen" or "python". When using strings, we need to enclose them in single or double quotes. We can use the inbuilt function "print" to display the output. If we want to print double quotes within a string, we can use single quotes to enclose the string and vice versa. To concatenate two strings, we can use the plus sign or multiply the string with a number to repeat it.

    Printing Paths

    • When printing paths like "C:/docs/naveen", we need to escape special characters like the forward slash (/) and the backslash (\) by using a backslash before them. Otherwise, Python may interpret them as new lines.

    #4 Python Tutorial for Beginners | Variables in Python

    Welcome back, 

    • on Python, we've covered what Python is, installed software, and worked with operations. In this video, we'll be discussing variables.

    What is a Variable?

    • A variable is a container where you can store values. For example, we can store 2 in a variable called "x".

      Variables are useful because they allow us to change the value of the container, and we can use them in operations. For instance, if we have x = 2 and y = 3, we can add them together: x + y = 5.

      Variables can store different types of values, such as integers and strings. We don't need to define the type of the variable since it automatically takes the value of whatever we assign to it.

    Example

    • x = 5
      y = "John"
      print(x)
      print(y)

    Example

    • x = 4       # x is of type int
      x = "Sally" # x is now of type str
      print(x)

    Example

    • x = str(3)    # x will be '3'
      y = int(3)    # y will be 3
      z = float(3)  # z will be 3.0

    Get the Type

    • You can get the data type of a variable with the type() function.

    Example

    • x = 5
      y = "John"
      print(type(x))
      print(type(y))

    Single or Double Quotes?

    • String variables can be declared either by using single or double quotes:

    Example

    • x = "John"
      # is the same as
      x = 'John'

    Case-Sensitive

    • Variable names are case-sensitive.

    Example

    • a = 4
      A = "Sally"
      #A will not overwrite a

    Variable Names

    • A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). Rules for Python variables:
      • A variable name must start with a letter or the underscore character
      • A variable name cannot start with a number
      • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
      • Variable names are case-sensitive (age, Age and AGE are three different variables)
      • A variable name cannot be any of the Python keywords.

    ExampleGet your own Python Server

    • myvar = "John"
      my_var = "John"
      _my_var = "John"
      myVar = "John"
      MYVAR = "John"
      myvar2 = "John"

    Many Values to Multiple Variables

    • Python allows you to assign values to multiple variables in one line:

    ExampleGet your own Python Server

    • x, y, z = "Orange""Banana""Cherry"
      print(x)
      print(y)
      print(z)

    Unpack a Collection

    • If you have a collection of values in a list, tuple etc. Python allows you to extract the values into variables. This is called unpacking.

    Example

    • fruits = ["apple""banana""cherry"]
      x, y, z = fruits
      print(x)
      print(y)
      print(z)

    Output Variables

    • The Python print() function is often used to output variables.

    Example Get your own Python Server

    • x = "Python is awesome"
      print(x)
      Try it »

      In the print() function, you output multiple variables, separated by a comma:

    Example

    • x = "Python"
      y = "is"
      z = "awesome"
      print(x, y, z)
      Try it »

      You can also use the + operator to output multiple variables:

    Example

    • x = "Python "
      y = "is "
      z = "awesome"
      print(x + y + z)
      Try it  »

      Notice the space character after "Python " and "is ", without them the result would be "Pythonisawesome".

      For numbers, the + character works as a mathematical operator:

    Example

    • x = 5
      y = 10
      print(x + y)
      Try it  »

      In the print() function, when you try to combine a string and a number with the + operator, Python will give you an error:

    Example

    • x = 5
      y = "John"
      print(x + y)

      The best way to output multiple variables in the print() function is to separate them with commas, which even support different data types:

    Example

    • x = 5
      y = "John"
      print(x, y)

    Using Variables in Operations

    • We can use variables in operations just like we do with numbers. For example, we can change the value of x from 2 to 9.

      We can also use underscores to represent the output of the previous operation. For example, if we add x + 10, we can use the output of that operation (19) in another operation: 19 + y = 22.

      We can also fetch individual characters from a string stored in a variable using square brackets. The numbering of characters starts at 0. For example, the first character of "youtube" is "y" and the last character is "e". We can also use negative numbers to start counting from the end of the string.

    Working with Strings in Python

    • Let's start by looking at how to access specific characters in a string using index values:

      • To access the first character, we use index 0.
      • To access the second character, we use index 1, and so on.
      • We can also use a colon to access a range of characters. For example, 0:2 will give us the first two characters.

      It's important to note that the ending value in a range is exclusive, meaning it will not be included in the result. If we want to access the first three characters, we would use 0:3.

      If we don't specify an ending value, the range will go until the end of the string.

      If we specify an ending value but not a starting value, the range will start at the beginning of the string.

      If we try to access characters outside the range of the string, we will get an error.

      While strings in Python are immutable, meaning we cannot change individual characters, we can concatenate strings and print them out in different ways.

      We can also use the built-in len() function to find the length of a string.

    #5 Python Tutorial for Beginners | List in Python

    Working with Lists in Python

    • Welcome back! In this video, we will be discussing how to work with lists in Python. A list is a collection of different values, such as numbers and strings, grouped together. Let's get started!

    Creating a List

    • To create a list, we use square brackets to enclose the values we want to include. For example:

      nums = [25, 12, 636, 95, 14]

      We can then print the list by typing nums. We can also access individual values within the list using their index number, starting from 0. For example:

      nums[0]

      This would print out the first value in the list, which is 25. We can also access values from the end of the list using negative index numbers. For example:

      nums[-1]

      This would print out the last value in the list, which is 14.

    Working with Different Types of Data

    • One of the great things about lists is that they can contain different types of data. For example, we can create a list like this:

      values = [9.5, "My name", 25]

      We can then access and manipulate this list just like any other list.

    List Operations

    • Lists are mutable, which means we can change their values and perform operations on them. For example, we can append a new value to the end of the list using the append() method:

      nums.append(45)

      We can also insert a new value at a specific index using the insert() method:

      nums.insert(2, 77)

      We can remove a value from the list using the remove() method:

      nums.remove(14)

      We can also use the clear() method to remove all values from the list, or the copy() method to create a copy of the list.

      There are many more methods and operations we can perform on lists in Python. Try them out for yourself!

    Working with Lists in Python

    • Lists are a powerful data structure in Python that can hold multiple values of different types. Here are some useful methods:

      • pop(): Removes and returns the last element in the list. If an index is specified, removes and returns the element at that index.
      • del: Deletes one or more elements from the list. To delete multiple elements, specify the starting and ending index.
      • extend(): Adds multiple values to the list. Specify the values in the parentheses.
      • sort(): Sorts the elements in the list in ascending order.
      • min(): Returns the minimum value in the list.
      • max(): Returns the maximum value in the list.
      • sum(): Returns the sum of all values in the list.

      To access elements in the list, use index values starting at 0. Lists are mutable, so values can be changed, added, or removed.

      Remember to consult the Python documentation for more information on these and other list methods.

    Python Lists


    • mylist = ["apple""banana""cherry"]

    List

    • Lists are used to store multiple items in a single variable.

      Lists are one of 4 built-in data types in Python used to store collections of data, the other 3 are Tuple, Set, and Dictionary, all with different qualities and usage.

      Lists are created using square brackets:

    Example Get your own Python Server

    • Create a List:

      thislist = ["apple""banana""cherry"]
      print(thislist)
      Try it  »

    List Items

    • List items are ordered, changeable, and allow duplicate values.

      List items are indexed, the first item has index [0], the second item has index [1] etc.


    Ordered

    • When we say that lists are ordered, it means that the items have a defined order, and that order will not change.

      If you add new items to a list, the new items will be placed at the end of the list.

      Note: There are some list methods that will change the order, but in general: the order of the items will not change.


    Changeable

    • The list is changeable, meaning that we can change, add, and remove items in a list after it has been created.


    Allow Duplicates

    • Since lists are indexed, lists can have items with the same value:

    Example

    • Lists allow duplicate values:

      thislist = ["apple""banana""cherry""apple""cherry"]
      print(thislist)
      Try it  »

      SPONSORED CONTENT

    List Length

    • To determine how many items a list has, use the len() function:

    Example

    • Print the number of items in the list:

      thislist = ["apple""banana""cherry"]
      print(len(thislist))
      Try it »

    List Items - Data Types

    • List items can be of any data type:

    Example

    • String, int and boolean data types:

      list1 = ["apple""banana""cherry"]
      list2 = [15793]
      list3 = [TrueFalseFalse]
      Try it  »

      A list can contain different data types:

    Example

    • A list with strings, integers and boolean values:

      list1 = ["abc"34True40"male"]
      Try it  »

    type()

    • From Python's perspective, lists are defined as objects with the data type 'list':

      <class 'list'>

    Example

    • What is the data type of a list?

      mylist = ["apple""banana""cherry"]
      print(type(mylist))
      Try it »

    The list() Constructor

    • It is also possible to use the list() constructor when creating a new list.

    Example

    • Using the list() constructor to make a List:

      thislist = list(("apple""banana""cherry")) # note the double round-brackets
      print(thislist)

    #6 Python Tutorial for Beginners | Tuple | Set in Python

    Python Tuples and Sets

  • Welcome back! In the last video, we talked about lists and we were supposed to complete tuples and sets, but due to time constraints, we will complete them in this video.

  • Tuples

  • A tuple is similar to a list, but it is immutable, which means you cannot change the value of a tuple. You can create a tuple by using round brackets and specifying the values inside them. Here is an example:

    tup = (21, 6, 14, 25)

    Once you specify the values in a tuple, you cannot change them. You can fetch values using square brackets, but you cannot change them. Tuples are useful in projects where you do not want to change the values of a list. Iteration in tuples is faster than in lists, so if you want to enhance the speed of your execution, you can use tuples.

  • Sets

  • A set is a collection of unique elements. You can create a set by using curly brackets and specifying the values inside them. Here is an example:

    s = {22, 25, 14, 21, 5}

    Sets do not follow a sequence, so the values are not sorted. You can fetch the values, but you cannot change them. Sets are useful when you do not need a sequence and you want to fetch elements as fast as possible using hash.

  • Recap

  • In summary, we learned that:

    • Lists are collections of values that can be of different types.
    • Tuples are similar to lists, but they are immutable.
    • Sets are similar to lists, but they are unordered and do not allow duplicates.
  • #7 Python Tutorial for Beginners | Python Set Path in Windows and Help

    Introduction

    • Welcome back  today we will be discussing Python. So far, we have covered the basics, but now we have a question. Until now, we have been using an IDE, but what if we want to use the command prompt?

  • Accessing Python on Command Prompt

    • Normally, when you work with shell or command prompt, you want to access Python. So, how do we do that? If we open the command prompt and type "python", we may get an error message saying "python is not recognized". This is because we have installed Python, but cmd is not able to get the path of it. To fix this, we need to specify the path ourselves. One way to do this is by using the command "set path", but this is only a temporary setting. If you want to make it permanent, you can do so by going to your C drive, right-clicking on the screen, selecting "properties", clicking on "advanced system setting", and then going to "environment variables". Here, you can set the path, but you will need to specify two parts: the first one, which you have mentioned, and the "scripts" part as well. Once you have done this, close everything and restart your command prompt. Now you should be able to access Python.

  • The Help Option

    • Python has certain modules that you can explore, but how do we know which modules are available? We can use the help option. To access this, simply type "help" and press enter. You can then type "topics" to see a list of available modules/topics. If you want to know about a specific topic, you can type "help" followed by the topic name in single quotes. This will give you information about the topic, including methods that can be used.

  • Conclusion

That's it for this video. We have covered how to set a path and how to explore the help option. Remember, reading the documentation is very important when it comes to improving your skills in Python. I hope you are enjoying this series. Let me know in the comments section and don't forget to hit the like button. Thanks for watching,


#8 Python Tutorial for Beginners | Python Editor | Sublime Text

Using Sublime for Python Code Execution

Welcome back! In this series on Python, we've been working with PyCharm, which is a great tool. However, some people prefer a lighter weight option, like Sublime. In this tutorial, we'll show you how to use Sublime for Python code execution.

Step 1: Download Sublime

First, you'll need to download Sublime. It's free to use, but if you want to use the full version, you'll need to purchase a license. Simply go to the official website or search for it on Google, and then click on the download button. Choose the appropriate version for your operating system and follow the installation steps.

Step 2: Open Sublime and Write Your Code

Once you have Sublime installed, open it up and start typing your Python code. You can save it anywhere you want, and give it a .py extension.

Step 3: Run Your Code

To run your code, go to the "Tools" menu and select "Build System" and choose "Python". Then, simply use the keyboard shortcut "Ctrl+B" to run your code. You should see the output in the bottom section of the screen.

That's it! You can use Sublime to execute any Python code you want.

#9 Python Tutorial for Beginners | More on Variables in Python

Python Variables and Memory Consumption

Welcome back to my Python series. In this video, we'll be discussing variables in a different way, focusing on memory consumption and what happens when you create multiple variables. Let's get started!

Understanding Memory Consumption in Python Variables

First, let's create a variable and assign a value to it. For example, let's say the variable name is "num" and the value is 5. Behind the scenes, this creates a box in your memory with the name "num" and an address, containing a value of 5. We can use the function "id" to get the address of the variable, which is unique to every variable.

Assigning Values to Multiple Variables

Now, let's create another variable "a" with a value of 10, and assign the value of "a" to a new variable "b". In Python, if multiple variables have the same value, they will point to the same box in memory to save space. However, if you change the value of one variable, it will no longer point to the same box and will create a new box in memory.

Understanding Constants in Python

In Python, constants are created by assigning a value to a variable and not changing it. This is useful when you want to ensure that a value remains the same throughout your program.

Constants in Python

A constant is a value that cannot be changed, similar to an immutable object. In C programming, you can create a constant variable, but in Python, you cannot. However, you can indicate your intention by using a different naming convention, such as capital letters. For example, pi value is a constant value in mathematics and can be named as "PI".

Although you cannot prevent someone from changing the value of a constant, you can make your intentions clear by using a naming convention that indicates that the variable should not be changed. In Python, you can use the type() method to determine the type of a variable. For example, if you want to know the type of the pi variable, you can type type(pi) and it will return float.

Variable Types in Python

Variables in Python have types, such as int and float. You can use the type() method to check the type of a variable. You can also create your own types, which we will cover in another tutorial. In the next video, we will discuss the different built-in data types in Python.

#10 Python Tutorial for Beginners | Data Types in Python

Data Types in Python

Welcome back! In this video, we'll talk about data types in Python. Understanding data types is important when working on a project because it allows you to process data in the correct format, preventing bugs and errors. The data types in Python include:

  • None
  • Numeric (int, float, complex, bool)
  • Sequence (list, range, set, tuple)
  • String
  • Map
  • Electron Coitus Dictionary

None

If a variable is not assigned a value, it is None in Python.

Numeric

Numeric types include int, float, complex, and bool.

  • Int represents whole numbers.
  • Float represents decimal numbers.
  • Complex represents a number plus an imaginary number.
  • Bool represents either True or False.

We can convert between numeric types using functions such as int(), float(), and complex().

Sequence

Sequence types include list, range, set, and tuple.

  • List is a collection of items in a specific order.
  • Range is a sequence of numbers.
  • Set is a collection of unique items.
  • Tuple is an ordered, immutable list.

Boolean

Boolean values represent either True or False. We can use comparison operators such as less than (<) and greater than (>) to get boolean values. True is represented by 1 and False is represented by 0 in Python.

Working with Data Types in Python

In Python, there are several data types available for use. Let's take a look at some of them:

List

To define a list, we use the keyword "list". For example:

s = [1, 2, 3, 4, 5]

We can also use set and tuple. To define a set, we use curly braces {}:

s = {1, 2, 3, 4, 5}

To define a tuple, we use parentheses ():

t = (25, 26)

String

To define a string, we use either double or single quotes:

str = "My name is Naveen"

Range

Range is used to iterate through a sequence of values.

r = range(10) # 0 to 9

We can also define a range with a specific start, end, and step:

r = range(2, 11, 2) # 2, 4, 6, 8, 10

Dictionary

Dictionary is used to assign a key to each value for easy retrieval. Keys must be unique.

d = {'Naveen': 'Samsung', 'Rahul': 'iPhone', 'Kiran': 'OnePlus'}

We can retrieve values using their keys:

d['Rahul'] # returns 'iPhone'


Comments

Popular posts from this blog

#22 Python Tutorial for Beginners | Break Continue Pass in Python

#19 Python Tutorial for Beginners | If Elif Else Statement in Python