Professional Documents
Culture Documents
Lab1 Basic
Lab1 Basic
Lab 1 Assignment
1. Strings
data = 'hello world' Q1.1 What is the letter of index 4 of data?
print(data[0]) Ans. O
print(len(data)) Q1.2 How is long of data?
print(data) Ans 11
print(type(data)) Q1.3 What is the data type of data?
Ans. string
1.1 Slicing: Slicing, in strings, refers to removing some part of a string.
name = 'Sonam' Q1.1.1 What is the output?
print(name) Ans. Sonam
name1=name[1:]
print(name1) onem
2. Numbers
value = 123.1 Q2.1 What is output of first print?
print(value) Ans. 123-1
print(type(value)) Q2.2 What is data type of first print?
value = 10 Ans. float
print(value) Q2.3 What is output of second print?
print(type(value)) Ans. 10
Q2.4 What is data type of second print?
Ans. int
3. Boolean
a = True Q3.1 What is output?
b = False Ans.
True False
print(a, b)
4. Multiple Assignment
a, b, c = 1, 2, 3 Q4.1 What is output?
print(a, b, c) Ans. 123
1
010243109 Introduction to Engineering by Amornphun Phunopas (APP)
Q4.2 Can variables be assigned in different type?
Ans. Yes
5. No value
a = None Q5.1 What is the value of a?
print(a) Ans. None
Lab 1 Problem
Output:
Enter the first number:15
Enter the second number:5
The two numbers are 15 and 5
The swapped numbers are 5 and 15
2
010243109 Introduction to Engineering by Amornphun Phunopas (APP)
Q4.2 Can variables be assigned in different type?
Ans.
5. No value
a = None Q5.1 What is the value of a?
print(a) Ans.
Lab 1 Problem
Output:
Enter the first number:15
Enter the second number:5
The two numbers are 15 and 5
The swapped numbers are 5 and 15
2
010243109 Introduction to Engineering by Amornphun Phunopas (APP)