LING 398
Elsayed Issa
Jingying Hu
Spring 2026

Lecture Plan (75 minutes):¶

  1. Questions, Installation troubleshooting, and command-line

  2. Python Basics

    • Variable assignment
    • Numbers
    • Boolean and the Logic operators
    • The None type
  3. Questions

3. Python Programming - Basics I

Objectives:¶

You will learn:

  1. Variable assignment.
  2. Basic object types:

    • strings
    • numbers
    • the None type
    • boolean
  3. Using some built-in fuctions:

    • print()
    • type()
    • isinstance()
    • int()
    • float()
    • complex()
    • bool()
    • str()

1. Variables and Variable Assignment

  • Variables help us to write flexible code.
  • In Python, the = symbol represents the assignment operator.
In [ ]:
name = "Salem"
print("Name:", name)
print("-----")
age = 20
print("Age:", age)
In [ ]:
print("Python is the greatest programming language!")
In [ ]:
my_name = "John Johnny"
print(my_name)
my_age = 100
my_age
In [ ]:
my_number_list = [1,2,3]
my_number_list

Varibale Names:¶

  • All varibale names are valid except starting with a numerical value or containing .. Both 3varibale and this.varibale are INVALID.
  • Variable names cannot contain one of the words reserved by python:
    • for, while, break, pass, continue, try, except
    • in, not, is, import, as, with, if, from, else
    • def, class, return, yield, raises, elif, finally

Practice:¶

  • valid vs. invalid variable name:
    • asd
    • as12
    • for
    • 123
    • None
    • 12_asd
    • num_py
In [ ]:
import re
def check(name):
    python_reserved_word = ["for", "while", "break", "pass", "continue", "try", "except", "in", "not", "is", "import", "as", 
                            "with", "if", "from", "else", "def", "class", "return", "yiled", "raises", "elif", "finally", "None"]
    if name in  python_reserved_word:
        return "Invalid"
    if not isinstance(name, str):
        return "Invalid"
    if not re.match(r'^[a-zA-Z_][a-zA-Z0-9_]*$', name):
        return "Invalid"
    return f"`{name}` is a valid varibale name."
In [ ]:
print(check("asd"))
print(check("as12"))
print(check("for"))
print(check("123"))
print(check("None"))
print(check("12_asd"))
print(check("course"))

2. Numbers

Types:

  • Integers

  • Floats

  • Complex numbers

2.1 Integers:¶

  • They are whole numbers: ..., -2, -1, 0, 1, 2, ...
In [ ]:
# an integer assigned to a varibale called int_number
int_number = 5

# print the value stored in the variable called int_number
print(int_number)

# what is the type of the value stored in the variable called int_number
print(type(int_number))
In [ ]:
my_phone_number = 726353536

type(my_phone_number)
In [ ]:
my_phone_number2 = "726353536"

type(my_phone_number2)
In [ ]:
converted = int(my_phone_number2)
type(converted)
In [ ]:
str(123)
In [ ]:
int(123)
In [ ]:
my_name = "123"
print(type(my_name))
In [ ]:
my_int_name = int(my_name)
print(my_int_name)
  • The built-in function int is used to identify the type of the integer and convert objects to integer.
In [ ]:
# 1) identify the type of the value stored in the variable called int_number 
# (we ask here if the type of value is int or not)
print(isinstance(int_number, int))

# 2) convert "10" to integer
example = "10"
print(type("10"))
print(int(example))

2.2. Floats:¶

  • They are decimal numbers: -0.24, 0.023
In [ ]:
# float number assigned to a varibale called float_number
float_number = 0.5983

# print the value stored in the variable called float_number
print(float_number)

# what is the type of the value stored in the variable called float_number
print(type(float_number))
  • The built-in function float is used used to identify the type of the float and convert objects to float.
In [ ]:
# 1) identify the type of the value stored in the variable called float_number 
# (we ask here if the type of value is float or not)
print(isinstance(int_number, float))

# 2) convert "10" to integer
example = 9
print(type(example))
print(float(example))
In [ ]:
n = 1
type(n)
In [ ]:
# can we make n a float?
float(n)

Question¶

  • Why do you think 1/3 == .33 returns False?

Please go to the following link: https://docs.python.org/3/tutorial/floatingpoint.html

In [ ]:
1/3 == 0.333

2.3. Complex¶

In [ ]:
# integer assigned to a varibale called complex_number
complex_number = complex(5)
print("Complex:", complex_number)
print("Type:", type(complex_number))
print("Type Verfied:", isinstance(complex_number, complex))
print()
In [ ]:
print(isinstance(55, int))
In [ ]:
print(isinstance("55", str))

Arithmetic Operators¶

Operator Meaning
+ addition
- subtraction
/ division
* multiplication
** exponentiation
// floor division
% modulus
In [ ]:
# addition
3 + 0.4
In [ ]:
# exponentiation
2**2
In [ ]:
# floor division -> the result rounds to the nearst integer 
21//2
In [ ]:
# modulus -> the result is the remainder of a division
a = 7
b = 2

a % b
In [ ]:
num_1 = 24
num_2 = 50

my_name = "John"

print(type(my_name))
print(type(num_1))
print(type(num_2))
In [ ]:
num_1 + num_2
In [ ]:
num_1 / my_name
In [ ]:
num_1**num_2

3. Boolean

  • There are two boolean-type objects: True and False; they belong to the built-in type bool. We have already seen that the isinstance function either returns True or False, as a given object either is or isn’t an instance of a specific type.

Comparison Operators¶

Operator Meaning
== equal
!= not equal
> greater than
< less than
>= greater than or equal to
<= less than or equal to
In [ ]:
# Is 5 > 6
5 > 6
In [ ]:
5 < 6
In [ ]:
# the two boolean-objects: `True` and `False`
type(True)
In [ ]:
# `False` is a boolean-type object
isinstance(False, bool)
In [ ]:
isinstance(True, bool)
In [ ]:
'hat' != 123
In [ ]:
#hat = 2
In [ ]:
hat != 123
In [ ]:
"hat" == "123"
In [ ]:
x = "hat"

x != "123"
In [ ]:
 

4. Logic Operators

  • Python provides familiar operators for performing basic boolean logic:
Operator Meaning
and returns True if both are True
or returns True if one is True
not reverse the output
In [ ]:
True & False
In [ ]:
# demonstrating boolean-logic operators
# and
print(True and False)

# another example
num1 = 3
print(num1 > 1 and num1 < 2)
In [ ]:
num_1 = 3
num_1 > 1
In [ ]:
num_1 < 2
In [ ]:
# or
print(True or False)

# another example
num2 = 3
print(num2 > 1 or num2 < 2)
In [ ]:
# not
print(not False)

# another example
num3 = 3
print(not(num3 > 1 or num3 < 2))

# example
print(not(num3 == 4))

5. The `None` Type

  • None is used a lot as a placeholder.
In [ ]:
type(None)
In [ ]:
v = 5
v is None
In [ ]:
v is not None
In [ ]:
my_name = None