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

Resume Python by Nassima

Uploaded by

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

Resume Python by Nassima

Uploaded by

amissanbennani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Comments in Python

• Single-line comments: Use # before the comment.

• Multi-line comments: Use triple quotes (""" or ''').

Variables in Python

1. Variable Naming Rules:

o Must start with a letter or an underscore (_).

o Cannot start with a number.

o Can only contain alpha-numeric characters and underscores (A-z, 0-9, _).

o Are case-sensitive (e.g., age, Age, and AGE are different).

o Cannot use Python keywords.

2. Assigning Values:

o Assign multiple variables in one line:

x, y, z = 1, 2, 3

o Assign the same value to multiple variables:

x = y = z = 10

3. Multiline String Assignment:

text = """This is

a multiline string."""

4. Check Data Type:

print(type(x))

Data Types

• Text Type: str

• Numeric Types: int, float, complex

• Sequence Types: list, tuple, range

• Mapping Type: dict


• Boolean Type: bool

• Binary Types: bytes, bytearray, memoryview

• None Type: NoneType

Examples:

x = 10 # int

y = 3.14 # float

z = 1j # complex

x = ["a", "b"] # list

x = ("a", "b") # tuple

x = range(6) # range

x = {"key": "value"} # dict

String Methods

• len(): Length of string.

• .upper(): Convert to uppercase.

• .lower(): Convert to lowercase.

• .capitalize(): Capitalize the first letter.

• .find(): Find position of a substring.

• .startswith(): Verify the beginning of a string.

• .endswith(): Verify the ending of a string.

Example:

text = "Hello, World!"

print(text.upper()) # HELLO, WORLD!

Control Structures

1. Conditions:

o Keywords: if, elif, else


o Comparison Operators: ==, !=, <, >, <=, >=

o Logical Operators: and, or, in, not in

Example:

if x > 10:

print("Greater")

elif x == 10:

print("Equal")

else:

print("Smaller")

2. Loops:

o Keywords: while, for, break, continue

Example:

for i in range(5):

print(i)

Input and Output

1. Print:

o print(): Display output.

o Format strings:

age = 14

price = 120.46

text = "Age: {} | Price: {:.2f}"

print(text.format(age, price))

2. Input:

o Single input:

name = input("Enter your name: ")

o Multiple inputs split into a list:


elements = input("Enter values separated by spaces: ").split()

print(elements)

Examples

1. List Initialization:

n = int(input("Number of items: "))

items = []

for i in range(n):

item = input(f"Enter item {i + 1}: ")

items.append(item)

print(items)

2. Split Input into List:

elements = input("Enter items separated by spaces: ").split()

print(elements)

You might also like