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

Python Basics: Functions and Input Handling

This document contains notes on various Python concepts: 1. Builtin functions can be viewed using dir(__builtins__). Python is case sensitive. Help can show function documentation. 2. Modules like math can be imported to use functions like math.sqrt. 3. User input can be obtained using input() and converted between int, float, and str as needed for arithmetic, comparisons, etc.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Python Basics: Functions and Input Handling

This document contains notes on various Python concepts: 1. Builtin functions can be viewed using dir(__builtins__). Python is case sensitive. Help can show function documentation. 2. Modules like math can be imported to use functions like math.sqrt. 3. User input can be obtained using input() and converted between int, float, and str as needed for arithmetic, comparisons, etc.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Python

Note 1: To see builtin funtions use below command:


dir(__builtins__)
Note 2: Python is case sensitive language
Note 3: To find builtin function functionality
Help(<builtin function>)
Note 4: There are multiple modules in python. To work with these
use below command to import modules.
Import <module name> ex: math
Ex: [Link](9)
User Input in Python: To read input values from prompt:
Ex: Variable = Name
Name = input(Enter your name: )
Print(Your Name is : +Name)

Converting sting to number:


Ex: Variable = age
age = int(input(Enter your age: ))
Print(Your age is: +age)

Concatenate string:
Ex: Print(Hello + World)

Converting number to string:


Ex: Print(Your age is: + str(28)) Or
Print(Your age is: +28)

Arithmetic Operations:
Ex:
5+5
55
5 / 3 -- Divide
5 % 3 -- Remainder (Modulo)

Conditional Statements:
IF:
name = "fish"
if name is "fish":
print("this is a fish");
Tab space is required for print

IF Else:
age = 25
if age > 50:
print("No need to see movies")
elif age < 17 and age > 12:
print("can see a rated PG-13 movie")
elif age == 25:
print("Can see all movies")
else:
print("can only see rated PG movie")
List: list that are less than 5.
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
num = int(input("Chose a number: "))
new_list = []

for i in a:
if i < num:
new_list.append(i)
print(new_list);
Division:
num = int(input("Please choose a number to divide: "))
listRange = list(range(1,num+1))
divisorList = []
for number in listRange:
if num % number == 0:
[Link](number)
print(divisorList)

You might also like