-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday4_python.py
More file actions
92 lines (61 loc) · 1.8 KB
/
day4_python.py
File metadata and controls
92 lines (61 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Day 4 of days of 30 challenge
## 📖 Lesson 1: Creating Strings
# Single quotes:
name = "hijabi"
print(name)
# Double quotes:
language = 'python'
print(language)
# Triple quotes:
bio = """Assalamualikum my name is hijabicoder and i am learning and doing ai automation my goal to create a free organization for begginers"""
print(bio)
# mostly double quotes use karte hein
# jb string MEIN quotes chahiye, tab opposite wala use karo
# or agar bhut sara text likhna hotw ek line mn tw triple quotes use kro
## 📖 Lesson 2: String Indexing
### Concept:
# Every character in a string has a position (index) starting from 0.
# ```
# P y t h o n
# 0 1 2 3 4 5
# ```
# You can access characters using square brackets: `text[0]`
# Negative indexing starts from the end: `text[-1]` gives last character
word = "programming"
# first word
print(word[0])
# last word
print(word[-1])
# fifth word
print(word[5])
## 📖 Lesson 3: String Slicing
### Concept:
# Slicing lets you extract parts of a string.
# **Syntax:** `string[start:end:step]`
# - `start` - where to begin (inclusive)
# - `end` - where to stop (exclusive)
# - `step` - skip characters (optional)
text = "Hello World"
# Get first 4 characters
print(text[0:4])
# Get last 4 characters
# print(text[:-4]) wrong yh last 4 ko htadaita hai
print(text[-4:])
# Reverse the entire string
print(text[::-1])
# Get every 2nd character
print(text[::2])
## 📖 Lesson 4: String Methods
# important method
text = " python is awesome "
# Convert to uppercase
print(text.upper())
# Convert to lowercase
print(text.lower())
# Replace "awesome" with "amazing"
# print(text.replace("awsome" , "amazing"))
print(text.replace("awesome", "amazing"))
# Strip whitespace
print(text.strip())
# Count how many spaces are in the text
print(text.count(" "))