0% found this document useful (0 votes)
3 views3 pages

Python Guide

This document provides an overview of Python's essential syntax, including functions, lambda functions, and lists of various dimensions. It also covers user input and different types of loops such as for loops and while loops. Examples are provided for each concept to illustrate their usage.

Uploaded by

i240608
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)
3 views3 pages

Python Guide

This document provides an overview of Python's essential syntax, including functions, lambda functions, and lists of various dimensions. It also covers user input and different types of loops such as for loops and while loops. Examples are provided for each concept to illustrate their usage.

Uploaded by

i240608
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/ 3

Python Syntax, Functions, Lambda, Lists, Input, and Loops

1. Python Functions

-------------------

Syntax:

def function_name(parameters):

Function docstring

statement(s)

return value

Example:

def greet(name):

return "Hello, " + name

print(greet("Alice")) # Output: Hello, Alice

2. Lambda Functions

-------------------

Syntax:

lambda arguments: expression

Example:

square = lambda x: x * x

print(square(5)) # Output: 25

add = lambda x, y: x + y

print(add(3, 4)) # Output: 7


3. Lists

--------

3.1 1D List:

lst = [1, 2, 3, 4]

print(lst[0]) # Output: 1

3.2 2D List:

matrix = [[1, 2], [3, 4]]

print(matrix[1][0]) # Output: 3

3.3 3D List:

cube = [[[1], [2]], [[3], [4]]]

print(cube[1][0][0]) # Output: 3

3.4 Complex Mixed List:

mixed = [1, [2, 3], [[4, 5], 6]]

print(mixed[2][0][1]) # Output: 5

4. Input

--------

# name = input("Enter your name: ")

# print("Hello", name)

# number = int(input("Enter a number: "))

# print("Square is", number * number)


5. Loops

--------

5.1 For Loop:

for i in range(5):

print(i) # Outputs 0 to 4

5.2 While Loop:

i=0

while i < 5:

print(i)

i += 1

5.3 Nested Loops:

for i in range(2):

for j in range(2):

print(f"i={i}, j={j}")

Conclusion:

This document gives an overview of Python's essential syntax for functions, lambda, lists of various types,

You might also like