0% found this document useful (0 votes)
7 views13 pages

Python Basics: Comments, Variables, Strings

PYTHON LESSON NOTE FOR SELF TAUGHT

Uploaded by

omotayojeremiah
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views13 pages

Python Basics: Comments, Variables, Strings

PYTHON LESSON NOTE FOR SELF TAUGHT

Uploaded by

omotayojeremiah
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

What is I.D.

E
An environment manager that allows users to easily install, update, and manage
different versions of Python, R, and their associated packages in isolated
environments. This prevents conflicts between project dependencies.

Installing IDE

Pycharm

Python 3.13

Anaconda

COMMENT

What is comment ?

Type of comment ?

# Single line comment

How to use comment?

DATA TYPE

Python is a dynamic data type i.e

Example

BASIC OPERATION

Result = 10 + 5

Product = 7-5

Quotient = 20 / 4

Power = 2** 3
VARIABLE AND CONSTANTS

How to define Constants and variable ?

# Declaring and assigning value to a constants#

PI =3.142326888

GRAVITY= 9.8M/S OR 10M/S

Declaring and assigning Value to a variable

a = “Apple”

Print(A)

Changing value of a variable

a= “areoplane”

Print (a)

a= 100

print(a)

Assigning multiple Value to a variable

b, c, d = 1, 2.5, “Hello”

print(b, c, d)

Assigning same Value to Multiple Variable

b=c=d=5

print(b, c, d)

CONDITIONAL STATEMENT

Age = 18
if age >= 18:

print (“You are an Adult.)

else:

print ( “ you are a child”)

INTRODUCTION TO [Link]

message = “Hello, python”

print(“Hello python”)

// Hello python is printed

String Concatenation

Greeting = “Hello”

Name = “python”

>>> Full_greeting = greeting + “ ” + name

>>> print (full_greeting)

// result will be “Hello Python”

String Method

It help to manipulate strings

text = “ python programming”

--------------------Create Space here

>>lower_case = [Link]()

>>upper_case = [Link]()

>>stripped_text = [Link]()

print(“lower case”, lower_case)

print(“upper case”, upper_case)

print(“stripped_text”, stripped_text)
RESULT:

lower case: python programming

upper case : PYTHON PROGRAMMING

stripped text: Python Programming

**Provide more Examples**

STRING OPERATION

text = “ Python Programming Language”

contains_python = “python” in text

length_of_text = len(text)

print(“contains ‘ python ’: ”, contains_python)

print(“length of text:”, length_of_text)

RESULT: True

27

**STRING-SLICING IN PYTHON**

String slicing is the process of extracting or getting a part of string, in python are
index

text = “python is awesome”

sliced_text = text[7:10]

print(“original text:”, text)

print(“sliced text:”, sliced_text)

Result:

Ex:
Create a text method

text = “programming is fun”

substrings1 = text[:11]

substrings2 = text[12:]

print(“substrings1: ”, substrings2)

print(“substrings2: ”, substrings3)

Quick Test Try: print(“substrings3 ”,)

SLICING NEGATIVE INDEXING

Create a text method

text = “programing ”

last_three_chars = text[-3:]

print (“original text:”, text)

print(“last three characters:”, last_three_chars)

Result

STRINGS MODIFICATION

String modification involves changing content of a string, in python strings are


immutable i.e. they cannot be changed directly.
Change Case of strings

text = “python programming”

lower_case = [Link]()

upper_case = [Link]()

title_case = [Link]()

print(“original text:”, text)

print(“lower case:”, lower_case)

print(“upper case:”, upper_case)

print(“title case:”, title_case)

More on STRING CONCATENATION

String concatenation is the fundamental ways of building a dynamic an expressive


string in your program

Is the process of combining or joining a string together, there are multiple ways to
join string.

greeting = “Hello”

name = “Sekinat”

concatenated_string = greeting + “ ” + name

print(“greeting:”, greeting)

print(“name:”, name)
print(“concatened string:”, concatenated_string)

Using Joint Method

words = [“Python”, “is”, “fun”]

result = “ ”.join(words)

print(“result”)

items = (“apple”, banana”, “cherry”)

result = “, ”. join(items)

print(“result”)

name = “python”

result = “-”.join(name)

print(“result”)

numbers = 1, 2, 3

convert first to strings

strings_numbers = [str(1,2,3) for num in numbers]

result = “-”.join(string_number)

print(“result”)
Loop Concatenation

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

Result = “ ”

For num in numbers:

Result += str(num)

print(“numbers:”, numbers)

print(“numbers:”, numbers)

print(“concatened result:”, result)


/* Reset */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
font-family: Arial, sans-serif;
line-height: 1.6;
background: #f9f9f9;
color: #333;
}

header {
background: #333;
color: #fff;
padding: 1rem 2rem;
}

header h1 {
display: inline;
}

nav ul {
list-style: none;
float: right;
}

nav ul li {
display: inline;
margin: 0 10px;
}

nav ul li a {
color: #fff;
text-decoration: none;
padding: 6px 12px;
border-radius: 4px;
transition: background 0.3s;
}

nav ul li a:hover,
nav ul li [Link] {
background: #ff6600;
}

.hero {
text-align: center;
padding: 100px 20px;
background: linear-gradient(120deg, #ff6600, #ffcc00);
color: white;
}
.hero h2 {
font-size: 2.5rem;
}

.btn {
display: inline-block;
margin-top: 20px;
padding: 10px 20px;
background: #333;
color: #fff;
border-radius: 6px;
text-decoration: none;
transition: background 0.3s;
}

.btn:hover {
background: #ff6600;
}

.content {
max-width: 800px;
margin: 40px auto;
padding: 20px;
background: white;
border-radius: 8px;
box-shadow: 0 0 8px rgba(0,0,0,0.1);
}

.contact-form {
display: flex;
flex-direction: column;
}

.contact-form label {
margin-top: 10px;
font-weight: bold;
}

.contact-form input,
.contact-form textarea {
margin-top: 5px;
padding: 10px;
border: 1px solid #ddd;
border-radius: 6px;
}

.contact-form button {
margin-top: 15px;
border: none;
cursor: pointer;
}

footer {
text-align: center;
padding: 15px;
background: #333;
color: white;
margin-top: 40px;
}

You might also like