Skip to content

Commit

Permalink
Changes on scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
rubada committed Feb 27, 2024
1 parent 7c9f97f commit 584b966
Show file tree
Hide file tree
Showing 86 changed files with 923 additions and 793 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# To define what variables are, let's take an example from real life, let's
# say you have a new friend, and you want to get his contact details, such as
# his name, phone number, his address etc., if want to memorize these details,
# his name, phone number, address, etc., if want to memorize these details,
# there is a chance that you can forget them, but if you save them in your
# phone, under your friend's name, then you can save them forever.
# This is the same as the variable in coding, where the objects (data,
# functions, classes etc.) are assigned to a name, and then the code can use
# functions, classes, etc.) are assigned to a name, and then the code can use
# this variable inside, without the need to define it every time.
# Also, data or values inside the variables may change, that is why they are
# Also, data or values inside the variables may change, which is why they are
# called variables.
# This leads us to the variables’ definition, which is, variables are temporary
# containers to store data.
# This leads us to the variables’ definition, which is, that variables are
# temporary containers to store data.


# To define a variable, use the "=" to assign any type of data to a specific
Expand All @@ -36,29 +36,29 @@
# print(weight_lbs)


# To define variables there are certain rules that should be followed:
# These rules can be applied to any name defined in python such as functions
# and classes names etc.
# 1. Variables should be start with a letter or underscore "_"
# To define variables certain rules should be followed:
# These rules can be applied to any name defined in Python such as functions
# and class names etc.
# 1. Variables should start with a letter or underscore "_"
_number = 55

# 2. After the letter or the underscore, letters, numbers or "_" can
# 2. After the letter or the underscore, letters, numbers, or "_" can
# be added.

n1 = 3.5
n_1 = 8

# Beware, to define a variable letters number and "_" are used, then numbers
# Beware, to define a variable letters, numbers, and "_" are used, numbers
# shouldn't be used as the first character in a variable name.
# Same rule apply to any name defined in Python.
# The same rule applies to any name defined in Python.

# 3n = 5
# n+time = 7
# hour@min = 66

# 3. In Python when defining any object with a name, (variables, classes,
# functions etc.), it should be taken in account that python is case sensitive,
# let's take an example:
# functions etc.), it should be taken into account that Python is
# case-sensitive, let's take an example:
my_name = "John"
my_nAme = "Mary"

Expand All @@ -72,18 +72,18 @@
# Print(My_name)


# In order to prevent errors when writing code, built-in objects should be
# written as they are defined inside Python, otherwise errors will be raised.
# To prevent errors when writing code, built-in objects should be written as
# they are defined inside Python, otherwise errors will be raised.

# 4. when defining a variable, the name given to it should be readable
# and spaces are not allowed,
# 4. When defining a variable, the name given to it should be readable
# and spaces are not allowed.
my_name = "John"
My_name = "Mary"
MyName = "Lilly"
# My Name = "Tom"

# Variables should be descriptive, anyone reads the variable should know what
# this variable is about and where it should be used.
# Variables should be descriptive, anyone who reads the variable should know
# what this variable is about and where it should be used.
rectangular_width = 5
rectangular_length = 10
rectangular_area = rectangular_width * rectangular_length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Why comments are important?
# Comments are used to explain the code and make your code readable
# and clear.
# Coments are used to prevent execution of some lines in your code.
# Comments are used to prevent the execution of some lines in your code.

# "a" is a string variable
# a = "This course is about Python"
Expand Down
14 changes: 7 additions & 7 deletions 01.Python_basics/1.Python_basics_scripts/03.Numbers/Numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
# print(b)
# print("b Type:", type(b))

'''we can't cast a complex number to int or float
uncomment below line and run code will give a typeerror'''
'''We can't cast a complex number to int or float
uncomment below the line and run code will give a type error'''
# c = int(z)

# print(c)
Expand All @@ -53,18 +53,18 @@
# print(int_num)
# print("int_num Type:", type(int_num))

# But if the the string is float number, using int() will raise ValueError,
# But if the string is a float number, using int() will raise ValueError,
# this error will be raised if an object cannot be converted to an integer,
# as shown in below example.
# as shown in the below example.
flot_str = "3.4"
# print(int(flot_str))

# int() function or constructor, syntax is as follows:
# int(x, base=10), to convert the a string to an integer and apply base 10 on
# int() function or constructor, the syntax is as follows:
# int(x, base=10), to convert the string to an integer and apply base 10 on
# it, the string should be integer not float otherwise an error will be raised,
# to solve this issue first change the number to a float then to an integer.

# Other bases such as 2 for binary system, and can be converted to an integer.
# Other bases such as 2 for a binary system, can be converted to an integer.
binary_num = "1101"

# print(int(binary_num, 2))
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# What are strings?
""" Strings are built-in class of data structure and it is imutable and use
""" Strings are built-in classes of data structure, it is immutable and uses
the "Unicode Characters" """

# Unicode Characters represent characters and symbols of different languages.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# String slicing is a method to create sub-string from the original string.
# String slicing is a method to create a sub-string from the original string.

a = "Hello World"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# String Mothods
# They are buitl-in methods used for string modifying or return True or False,
# we will learn most used methods.
# To know more about these mehtods check Python documentation or any other site
# String Methods
# They are built-in methods used for string modifying or returning True or
# False, we will learn the most used methods.
# To know more about these methods check Python documentation or any other site
# that you prefer:
# https://docs.python.org/3/library/stdtypes.html#string-methods

a = "Python is a Wide. used Programming. Language"

# Note, methods (for lists, strings, dictionary etc.) are written on the right
# Note, methods (for lists, strings, dictionary, etc.) are written on the right
# side of the object after the ".", as shown in below syntax:
# object.method()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# print(sent)

# 2. String formatting
# There are two ways to format the string
# There are two ways to format the string:
# 1. Using the format() method
year = "2023"
day = "24"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# Escape Characters:
# Are used to insert special charaters lines etc. into a string or code by
# Are used to insert special characters lines etc. into a string or code by
# using \ Backslash.
# There are many escape characters used in Python, and we will discuss the
# most used.
# There are mnay sites explain the esacpe characters in python, and show
# There are many sites that explain the escape characters in Python, and show
# how to use them, you can check them out.

# 1. \" or \'
# The back slash is used to allow us use single or double quotes inside the
# The backslash is used to allow us to use single or double quotes inside the
# string as shown below:
a = 'I\'m taking this python course'
a = 'I\'m taking this Python course'
# print(a)

b = "This course is about \"Python\""
# print(b)

# Using differnet quotes (single or doubles) as string quotes and quotes inside
# Using different quotes (single or doubles) as string quotes and quotes inside
# the string, will not give and error as shown below.
# c = "This course is about 'Python'"
c = 'This course is about "Python"'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Booleans
# Booleans return two values, True or False
# Boolean often used in if else statements, which will be covered later.
# Boolean is often used in if-else statements, which will be covered later
# in the future

# Examples
Expand All @@ -14,7 +14,7 @@

# We can use the bool() function to check for "True" or "False"
# Almost every object in Python returns "True", unless they are 0 or an
# empty objects, such as (emplty strings, empty lists, empty dictionaries,
# empty objects, such as (empty strings, empty lists, empty dictionaries,
# etc.), which they will return "False", as shown below:

# All strings return True value unless it is not an empty string:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# y -= 1
# print(y)

# Comparison Operators ==, !=, >, <, >=, <=, used in if statement and
# Comparison Operators ==, !=, >, <, >=, <=, used in if-statement and
# other logical or function and method
a = 7
b = 8
Expand All @@ -28,7 +28,7 @@
# print(7 >= a)
# print(8 <= b)

# Logical Operators, used in if statement and other logical function and
# Logical Operators, used in if-statement and other logical function and
# methods
# print(a == b and b > a)
# print(a <= b or b <= a)
Expand All @@ -51,6 +51,6 @@
# print(5 ^ 9)
# print(5 << 2)

# ~4 means not 4, which change all zeros to ones and all the ones to zeros and
# ~4 means not 4, which changes all zeros to ones and all the ones to zeros and
# return the real number
# print(~4)
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
# Identity Operators
# Data in python are represented by objects.
# Each object has an identity, value and type.
# Data in Python are represented by objects.
# Each object has an identity, value, and type.
# For example:
a = "Python"
# "a" has a string type and value of python, then what is the identity?
# Object identity is the object address in memory, each object has a memory
# location once its created.
# location once it is created.

# Identity operators are special comparison operators, used to compare if two
# variables have the same object in memory.
# They don't compare the values of the variable like the equal operator ==
# but compare the memory address.

# There are two identity operators:
# "is" return True if both variables are the same object and has the same
# "is" returns True if both variables are the same object and have the same
# memory address, and False if not.
# "is not" return True if both variables are not the same object and doesn't
# "is not" return True if both variables are not the same object and don't
# have the same memory address, and False if not.
# Identity operators works with with different type of objects such as string,
# lists, numbers, tuples etc.
# Identity operators work with different types of objects such as strings,
# lists, numbers, tuples, etc.
# To check the memory address we use the id() function.

# Identity operators and function are important when working with large
# data structure because it leads to conserve memory. How?
# Identity operators and functions are important when working with large
# data structures because they lead to conserving memory. How?
# Example:

b = [6, 3]
Expand All @@ -32,8 +32,8 @@
# print(b is c)
# print(d is b)

# d = b is not a proper way to copy list because d and b are the same object,
# any change in d will affect b
# d = b is not a proper way to copy a list because d and b are the same object,
# any change in d will affect b.
# d.append(5)
# print(b)
# print(d)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# User Input
# The user input is used inert data from the user and convert it to a string,
# The user input is used inert data from the user and converted it to a string,
# then this string is used in the code.
# Use the input() to insert data to your Python code.
# Let's take and example:
# Use the input() to insert data into your Python code.
# Let's take an example:

# name = input("Please type your name: ")
# print(f'Hi {name}, How are you?')

Expand All @@ -17,7 +18,7 @@
# print("number type: ", type(decimal_num))


# # Input function can be used in loops
# Input function can be used in loops
# list_numbers = []
# n = 1
# while n != 0:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
# Lists
# A list is a built in sequence, that is used to store a collection of data.
# In other programing they are sometimes called array.
# A list is a built-in sequence, that is used to store a collection of data.
# In other programming they are sometimes called arrays.
# We can store any type of data in a list such as:
# Numbers, strings, booleans, sets, dictionaries, tuples and lists.
# Numbers, strings, Booleans, sets, dictionaries, tuples, and lists.
# Example:

my_list = [9, "cat", 9.7, "dog", [False, True, None], 9]
# print(my_list)

# list type is a class object
# print(type(my_list))

# List rules:
# 1. Lists are ordered, when adding values to a list it will be added
# 1. Lists are ordered, when adding values to a list they will be added
# at the end of the list
# 2. Lists are mutable, objects inside a list, can be modified, and can be
# added or removed.
# 3. Lists can have duplicates objects.
# 3. Lists can have duplicate objects.

# We can use the len() function to get the list length
# print(len(my_list))

# How can we define a new list?
# 1. Using the square brackets [] by assign it to a variable, creating an empty
# list and then it can be filled with any type of data.
# 1. Using the square brackets [] by assigning it to a variable, creating an
# empty list and then it can be filled with any type of data.

a = []

# 2. Using the list() contructure or function to define a new list
# 2. Using the list() constructor or function to define a new list.
b = list()

# we can use the list() to change a different data type to list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
# print(my_list[4][1])
# print(my_list[4][2])

# Lists are iterables, loops can be used to iterate on lists objects.
# Lists are iterable, loops can be used to iterate on list-objects.
# for i in range(len(my_list)):
# print(my_list[i])

# for item in my_list:
# print(item)

# Loop over the sub list, as shown below:
# Loop over the sub-list, as shown below:
# for i in range(len(my_list[4])):
# print(my_list[4][i])

Expand All @@ -33,7 +33,7 @@
my_list = [9, "cat", 9.7, "dog", [False, True, None], 9]

# Lists Slicing
# The same string rules are applied on lists
# The same string rules are applied to lists.
# a. a[start:stop]
# Indexing will begin from "start" through "stop-1".

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Change Items in Lists
my_list = [9, "cat", 9.7, "dog", [False, True, None], 9]

# changing items by index number
# changing an item by using the index number
# my_list[2] = "mouse"

# print(my_list)
Expand Down
Loading

0 comments on commit 584b966

Please sign in to comment.