Python Beginner Tutorial
Jackolanternexe (70)

Before we begin:

I couldn't find any other basic Python tutorials so I decided to make one, but I apologize if there are any other tutorials that I missed out there. Thanks!
Also: feel free to give constructive criticism. If this is helpful, please comment below, and consider sharing it and upvoting. If people enjoy this tutorial, I might make another one for intermediate users.


TABLE OF CONTENTS

  • What is Python?
  • What is Python used for?
  • Printing
  • User Input
  • Data Types
  • Loops
  • Summary
  • Citations

WHAT IS PYTHON?

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. It's high-level built-in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together. Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse. The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms and can be freely distributed. It was created in 1991 by Guido van Rossman.


WHAT IS PYTHON USED FOR?

Python is a very versatile language and has many applications. Some of the uses include:

  • Web and Internet Development
  • Scientific and Numeric
  • Education
  • Desktop GUIs
  • Software Development
  • Business Applications

PRINTING

Let's start with Pythons most basic command; the print("") function. Let's take a closer look.
The print("") function prints the specified message to the screen or other standard output device.
The message can be a string or any other object, the object will be converted into a string before written to the screen.

Summary
The print function prints a specified message in the terminal.


USER INPUT

The input() function allows user input.
Example:

x = input()
print('Hello, ' + x)

Summary
When we prompt the user to input data, then save that input as a variable and use it when the variable is called upon.


DATA TYPES

Strings
A string object is one of the sequence data types in Python. It is an immutable sequence of Unicode characters. Strings are objects of Python's built-in class 'str'. String literals are written by enclosing a sequence of characters in single quotes ('hello'), double quotes ("hello") or triple quotes ('''hello''' or """hello""").

The escape character is used to invoke an alternative implementation of the subsequent character in a sequence. In Python, backslash \ is used as an escape character.

String examples:
"Hello" 'Hello'

Integers
Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.
Examples:
22 -40 100050

Floats
Float, or "floating-point number" is a number, positive or negative, containing one or more decimals.
Examples:
22.2 -40.4 100.0

Booleans
A piece of data that equals TRUE or FALSE.
You can evaluate any expression in Python, and get one of two answers, True or False.
Examples:
Input code:
print(10 > 9) print(10 == 9) print(10 < 9)
Output:
True False False

Dictionaries
A dictionary is a collection which is unordered, changeable, and indexed. In Python, dictionaries are written with curly brackets, and they have keys and values.
Example:
thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 }

Lists
A list is a collection that is ordered and changeable. In Python, lists are written with square brackets.
Example:
thislist = ["apple", "banana", "cherry"]

Tuples
A tuple is a collection that is ordered and unchangeable. In Python, tuples are written with round brackets.
Example:
thistuple = ("apple", "banana", "cherry")

Summary
There are many different types of data. Strings are any characters, integers are numbers without decimals, floats are numbers WITH decimals, booleans are true or false values, tuples are a collection ordered and unchangeable, lists are a collection ordered and changeable, and a dictionary is unordered, changeable, and indexed.


LOOPS

Python has two loop commands:
-while loops
-for loops

While loops
With the while loop, we can execute a set of statements as long as a condition is true.
Example:

# print i as long as i is less than 6
i = 1
while i < 6:
  print(i)
  i += 1

With the break statement, we can stop the loop even if the while condition is true.
Example:
Exit the loop when i is 3:

i = 1
while i < 6:
  print(i)
  if i == 3:
    break
  i += 1

For loops
A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).
This is less like the for a keyword in other programming languages and works more like an iterator method as found in other object-orientated programming languages.
With the for loop, we can execute a set of statements, once for each item in a list, tuple, set, etc.
Example:
Print each fruit in a fruit list:

fruits = ["apple", "banana", "cherry"]
for x in fruits:
  print(x)

With the break statement we can stop the loop before it has looped through all the items:
Exit the loop when x is "banana":

fruits = ["apple", "banana", "cherry"]
for x in fruits:
  print(x)
  if x == "banana":
    break

Summary
Like data types, the different types of loops are appropriate for different types of situations.
While loops continue until a certain value is false.
A for loop is used for iterating over a sequence. With the for loop, we can execute a set of statements, once for each item in a list, tuple, set, etc.


SUMMARY

Python is a language with a lot of functions. This tutorial only covers the bare basics, and there are a lot more functions. In fact, we really only got around to basic syntaxes. However, I hope this can help you if you have never used Python before. Thanks!
~ Jackolantern


CITATIONS

Wikipedia Contributors. Python (programming language). Wikipedia. https://en.wikipedia.org/wiki/Python_(programming_language). Published May 10, 2020. Accessed May 10, 2020.

What is Python? Executive Summary. Python.org. https://www.python.org/doc/essays/blurb/. Published 2020. Accessed May 10, 2020.

Applications for Python. Python.org. https://www.python.org/about/apps/. Published 2020. Accessed May 10, 2020.

W3Schools Online Web Tutorials. W3schools.com. https://www.w3schools.com/. Published 2020. Accessed May 10, 2020.


You are viewing a single comment. View All
maya1909021 (0)

you're a g for this thanks