-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariables in Python
More file actions
56 lines (42 loc) · 1.42 KB
/
Copy pathVariables in Python
File metadata and controls
56 lines (42 loc) · 1.42 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
// we can directly assign value to the variables irrespective of datatype
x=3
y=2
x
output is 3
x+y
output is 5
x=9
x+y // the new value of x is replaced with 3
output is 12
_+y // here _ is used to take the value of previous output
output is 14
name='python'
name+'code'
output is 'python code'
name='python'
name[1] // the characters get stored in array and here 1 is index of array.....It's all pre-defined
output is 'y'
name='python'
name[-2] // the characters get stored in array and here -2 is index of array from end.....It's all pre-defined
output is 'o'
name='python'
name[0:2] // the characters get stored in array and characters from 0th index upto 2nd index gets printed(2nd index is not included)
output is 'py'
name='python'
name[2:] // the characters get stored in array and characters from 2nd index upto end
output is 'thon'
name='python' // first four characters
name[:4] // the characters get stored in array and characters from 0th index upto 4th index (4th index is not included)
output is 'pyth'
// Strings in python are immutable (you can't even change a single character)
// but, if
name='python code'
print('java' + name[7:])
output is 'javacode'
print('java ' + name[7:])
output is 'java code'
name='python code'
len(name) // pre-defined method to find length of string
output is 11 // space is also counted
print(r'Hello \n Friends')
output=?? // Quiz Question