Giter VIP home page Giter VIP logo

python3.11-tutorial's Introduction

kisspng-professional-python-programmer-computer-programmin-python-logo-download-5b47725c1cc0d6 3474912915314089881178-removebg-previewPython Timekisspng-professional-python-programmer-computer-programmin-python-logo-download-5b47725c1cc0d6 3474912915314089881178-removebg-preview

situation bagde GitHub Repo stars

Typing SVG

man-kissing-snake

πŸ“… Contents

πŸ“¦ VSCode and Python Extension

1) Install VSCode

Firstly, we need to download Visual Studio Code. Visual Studio Code is a streamlined code editor with support for development operations like debugging, task running, and version control. Go to the website: https://code.visualstudio.com/Download For the video about downloading: https://youtu.be/Dnw27nTX66o?t=22

Download VSCode

2) Install Python 3.11

Secondly, we need to download Python. Python is an interpreted, object-oriented, high-level programming language with dynamic semantics developed by Guido van Rossum. We download it to use this software language on our device. Go to the website: https://www.python.org/downloads/

Download Python

3) Install Python Extension to VSCode

Last step: install python extension to VSCode. This allowed us to write, run and debug python commands on VSCode. To do this step, you can watch the video or follow the images. Video link: www.youtube.com

Step 1: Click Extentions Icon Download Python Extension

Step 2: Write Python to the Search Box Download Python Extension

Step 3: Install the Python Extension Download Python Extension

πŸ¦‰ Let's Start!

In this section, I will write and show some code lines one by one. You will see examples and explanations and if you want to get the code, you can reach them above.

Create a Python (.py) File

Step 1: Click the Open Folder Button
Step 2: Create a Folder Create a Python Folder

Step 3: Click the button
Step 4: Write a name for file and end it with ".py" (example_name.py) Create a Python File

Step 5: Sit back and realize you're ready! 😁 Download Python Extension

πŸ±β€πŸ‘€ First Lines

1) print

Uses to output to the screen. Usage:

print("Can you hear me?")

This will write Can you hear me? to the terminal

2) input

It allows us to use it in the program by entering data from the terminal

input("Write your name: ")

This will write Write your name: and will wait until you write anything

3) if

It allows us to create condition block

if 5 > 2:
  print("This is true!")

This will write This is true! because if condition is right (As we know, 5 is bigger than 2). So how do we do it if it's wrong?

4) if-else

It allows us to create condition block

if 2 > 5:
  print("This is true!")
else:
  print("This isn't true!")

This will write This isn't true! because if condition isn't right (As we know, 2 isn't bigger than 5). So how do we do it if it's equal?

5) if-elif-else

It allows us to create condition block with different possibilities

if 2 > 2:
  print("This is true!")
elif 2 == 2:
  print("They are equal")
else:
  print("This isn't true!")

This will write They are equal because if condition isn't right and elif is right. (As we know, 2 equal 2 😁). So how do we do cheack them? For example we used "==" in our "elif" section. Before talk about them, I need to show one more thing.

6) if-elif-...-elif-else

It allows us to create condition block with more different possibilities

if 2 > 2:
  print("This is true!")
elif 2 == 2:
  print("They are equal")
.
.
.
elif 2 != 2:
  print("They aren't equal")
else:
  print("This isn't true!")
Explanation

This will write They aren't equal because if-second elif condition isn't right and first elif is right. We used "!=" in our "elif" section. As the other example, we can check some conditions. These "==" and "!=" some examples of what we use. Until now, you learned the print something to the screen, you learned to use input and you see the if-elif-else condition blocks. To learn and understand these blocks too, we need to learn something more πŸ˜„

πŸ“œ Data Types

In this sections, you will see explanations about data types. Thus you will understand variables and data types. After this sections, you will see explanations about variables. Shortly, we use them to store or use datas in our program or code.

1) str

This data type is using for string datas. For example, if you want to add your name or any kind of string data your variable will be str data.

"Earth" is a string(str) data.

2) int

This data type is using for integer datas. For example, if you want to use your age in your program it will be int data.

13 is a integer(int) data.

3) float

This data type is using for decimal number datas. For example, if you want to use temperature in your program this data will be float.

303.1 is a float data.

4) bool

This data type is using for understanding something is True or False. We generally use them with loops.

5) list

This data type is using for collecting datas under a list. You can think it like your "shopping list", that's mean your "shopping list" is a list data. In python we use "[" and "]" for define them.

["book","cd","food","water"]

⭐) Comment Line

If you want to add line which won't use by program, you can write them with "#". It's name is comment line because developers use them for adding note their programs. But if your comment will be longer than 4-5 lines you have another option to make them comment line, It's "" "" . Let's look at the example below.

  print("Where I am?") # This is comment line too but if I do like this, my print command will work but as the other this part won't run by program
β€Ž```And this is the comment block in PythonYou can write a lot of lines into thisβ€Ž```

🎨 Variables

As I told before, we use variables to store or use datas in our program or code. Let's see how we use them.

1) The Variables We Set

We can define variables when we write the code.

name = "Apple"                       # str (String)
myNumber = 5                         # int (Integer)
your_ number = 0.2                   # float (Float)
ourList = ["apple","orange","grape"] # list (List)

2) The Variables Receiving Data From User

We don't have to define variable with their values. Let's get values from user.

name = input("What is your name? >")
Explanation

But there is a difference. If user write there 6, this data won't be string. Until you write an answer to your input command, "name" will be "NoneType". You can think that's undefinied. But when you write and hit the enter, it will be changed.

3) Using Datas From User

We can use data came from user. In this example we will use f string. We can use our variables in the texts we wrote with this string type. Looks like that print(f"{variable_name}")

name = input("What is your name? >")

print(f"My name is {name}") # Output will be "My name is (your input)" 
Explanation

If you want to print your name here, you have to write your variable which gets your name.

⭐) Print Data

We can print our datas by their variable.

myName = "Apple"
yourName = input("What is your name? > ")
  
print(myName)    # Apple writes. 
print(yourName)  # It will write your input

βž• Operations

In this sections, you will see some common operations but they won't be all of them. For more look at the table and go for full document.

1) ==, !=

We use these operator for check the values or datas are equal or not and returns True or False. Let's learn with the examples. In this example I will use with print but of course, you can use different ways.

x = 5
y = 10
print(x == y) # Prints "False" (== -> Are they equal?)
print(x != y) # Prints "True"  (!= -> Are they not equal?)

2) +, -, /, *

We use these operator for basic mathematical calculations.

x = 47
y = 38
print(x + y) # Prints "85"
print(x - y) # Prints "9"
print(x / y) # Prints "1.236842105263158"
print(x * y) # Prints "1786"

3) <, >

We use these to returns True or False. They control the values like == and !=.

x = 50
y = 30
print(x > y) # Prints "True"
print(x < y) # Prints "False"

4) and and or

We use these operator for creating more complex conditions.

x = 50
y = 30
print(x > y and x == 50) # Prints "True". Because x > y is true and x == 50 returns true too. Then the result is true.
print(x < y or y == 30) # Prints "True". Because y = 30. In "or" operation, just one true enough for returning true.
Explanation print(x > y and x == 50) # Prints "True". Because x > y is true and x == 50 returns true too. Then the result is true. print(x < y or y == 30) # Prints "True". Because y = 30. In "or" operation, just one true enough for returning true.

⭐) Table From Document

Click on the Image to go to the source. Table from Python Website

➰ Loops

In this section, we will learn about loops. After this section, you will be ready for examples and more!

1) For Loops with Lists

It's our the first loop type.

# for {variable name for each element} in {element's resource}:
#   {we can do anything we want}

list = ["book","cd","food","water"]

for name in list:
  print(f"This is {name}")
Explanation

This loop will run the print command for four times because our list have four element and name variable will be write different for each tour.

This is book This is cd This is food This is water

2) While

It's our the second loop type.

  # while ({condition}): # if the condition returns "True", loop will start and 
  #   {we can do anything we want}
  
  a = 10
  
  while (a > 5):
    print(f"A euals {a}")
Explanation

If you do like this, you code will run until you close it or forever :D To avoid this problems and handle the loops better we will learn these break, continue.

break and continue

  a = 10
  b = 0
  
  while (a > 5):
    print(f"A euals {a}")
    
    b = b + 1       # b will increase one each tour
  
    if b == 5:
      break         # loop will end on this line
    else:
      continue      # loop will continue when the b isn't equal 5
  
  
  # In this loop, when the name equals to "food", loop will end
  
  list = ["book","cd","food","water"]

  for name in list:
    if name == "food":
      break
    else:
      continue

πŸ€ΈπŸΌβ€β™‚οΈ Converting Data Types

We will learn the data types and their conversions.

1) type({variable_name})

This command helps us to understand the variables types. Let's see in an example.

name = "Alice"
age1 = "18"
age2 = 18
age3 = 18.5
names = ["Alice", "Bob", "Larry"]
tutorial_is_good = True

print(type(name))               # name = "Alice"                    -> <class 'str'>
print(type(age1))               # age1 = "18"                       -> <class 'str'>
print(type(age2))               # age2 = 18                         -> <class 'int'>
print(type(age3))               # age3 = 18.5                       -> <class 'float'>
print(type(names))              # names = ["Alice", "Bob", "Larry"] -> <class 'list'>
print(type(tutorial_is_good))   # tutorial_is_good = True           -> <class 'bool'>
  
# Tip
print(name + age1)        # Works because we can collect str types
print(name + " " + age1)  # Works because we can collect str types
printf(name + age2)       # Doesn't Work we can't collect str and int types
print(name + " " + age2)  # Doesn't Work we can't collect str and int types

2) Converting the Data Types

str() int() float() bool()

name = "Alice"
age1 = "18"
age2 = 18
age3 = 18.5
names = ["Alice", "Bob", "Larry"]
tutorial_is_good = True
  
print(name + age1)        # Works because we can collect str types
print(name + " " + age1)  # Works because we can collect str types
printf(name + str(age2))       # Doesn't Work we made the age2's type str
print(name + " " + str(age2))  # Doesn't Work we made the age2's type str

  
a = "True"

print(type(a))
print(type(bool(a)))

🐍 Examples1

1️⃣ Input-Print-Example-1

name = input("Please write your name: ")
print(f"\nHi {name}, It's nice to see you. Did you drink enough water today? ")
water = input("? > ")
print(f"It's important {name}, Studies show that an adult woman should drink 2.7 liters of fluid per day, and a man 3.7 liters. But softwares not ^-^")

2️⃣ Input-Print-Example-2

print("This program write a automatic self introduction text.\nLet's start!")
  
name = input("What is your name? > ")
surname = input("\nWhat is your surname? > ")
age = input("\nHow old are you? > ")
country = input("\nWhere do you live? > ")
job = input("\n")
note = input("\n")
  
print("\n\nHi! It's {name} {surname}. I am {age}. I live in {country} and I do {job} for living. Finally, {note}.")

3️⃣ If-Else-Example

print("This is a grade checker.\nYour first test has an impact rate of 40%, your second test has an impact rate of 60%.\nWrite your scores and see your result.\nIf you have lower than 40, you will be unsuccesful.\n(Grades must be between 0-100)\n")
  
firstTest = input("Your first test score: ")
secondTest = input("Your second test score: ")
  
result = (firstTest*40)/100 + (secondTest*60)/100
  
if result > 40:
  print("\nYou passed the class\n")
else:
  print("\nYou didn't pass the class\n")

4️⃣ If-Elif-Else-Example-2

print("This is a grade checker.\nYour first test has an impact rate of 40%, your second test has an impact rate of 60%.\nWrite your scores and see your result.\nIf you have lower than 40, you will be unsuccesful.\n(Grades must be between 0-100)\nAt this program, your grade will handle different")
  
firstTest = input("Your first test score: ")
secondTest = input("Your second test score: ")
  
result = (firstTest*40)/100 + (secondTest*60)/100
  
if result >= 90:
    print("\nYour grade is equal or more than 90\n")
elif result < 90:
    print("\nYour grade is lower than 90\n")
else:
    print("\nAn error occured\n")

5️⃣ If-Elif-Else-Example-3

This example is purposely kept long, let's learn to make it shorter.

print("This is a grade checker.\nYour first test has an impact rate of 40%, your second test has an impact rate of 60%.\nWrite your scores and see your result.\nIf you have lower than 40, you will be unsuccesful.\n(Grades must be between 0-100)\nAt this program, your grade will handle different")
  
firstTest = input("Your first test score: ")
secondTest = input("Your second test score: ")
  
result = (firstTest*40)/100 + (secondTest*60)/100
  
if result >= 90:
    print("\nYour grade is equal or more than 90\n")
elif result < 90:
    if result >= 70:
        print("\nYour grade is equal or more than 70\n")
    elif result < 70:
        if result <= 50:
            print("\nYour grade is lower than 70\n")
        elif result < 50:
            print("\nYour grade is equal or more than 50\n")
else:
    print("\nAn error occured\n")

5️⃣ If-Elif-Else-Example-4

We can do the same progress with operation like "and" and "or".

print("This is a grade checker.\nYour first test has an impact rate of 40%, your second test has an impact rate of 60%.\nWrite your scores and see your result.\nIf you have lower than 40, you will be unsuccesful.\n(Grades must be between 0-100)\nAt this program, your grade will handle different")
  
firstTest = input("Your first test score: ")
secondTest = input("Your second test score: ")
  
result = (firstTest*40)/100 + (secondTest*60)/100
  
if result >= 90 and result < 90:
    print("\nYour grade is equal or more than 90\n")
elif result >= 70 and result < 70:
    print("\nYour grade is equal or more than 70\n")
elif result <= 50:
    print("\nYour grade is lower than 50\n")
else:
    print("\nAn error occured\n")

You can send me your questions or examples in comment, maybe I can add them to the tutorial. Thank you for your interest. To improve your code, you can use the "Comment" section. Don't worry and don't hesitate, we all trying to improve ourselves ^-^

python3.11-tutorial's People

Contributors

berattezer avatar

Watchers

 avatar

Forkers

musikman21

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.