python programming day- 6 quick start type casting and uses of string
what is type casting?
type casting is a method for changing or conversion of one data types to another data types with certain rules and regulation
there are two types of type casting
1 explicit : the conversion of data made by user by using command
for example str in to int
float in to int
some code for explicit type casting
a = "100"
b = "200 "
c = 10
d = 10.1
#it is both data are string value
print (int(a) + int(b)@int)
print (int(a) + int(c) )
print (int(a) + int(d))
*****this will return int value*****
what is string ?
string is a set data which contain text , numeric ,or float data as a string
string is normally use as "vishal" or 'vishal' /"123"/"10.1"
we can use multiline string using """ """ this command for example
a = """रगत त सबैको रातै नै हुन्छ।
हो, सानै देखि उसले यस्तै देखेको छ।
जयन्तकृष्ण फगत् एक्लै
आफैंसँग बात मार्छ: प्रश्न गर्छ, उत्तर दिन्छ
आफैं प्रतिवाद गर्छ –
रगत सबैको साँच्चै नै उत्तिकै रातो हुन्छ नि !
कसरी हुन्छ त त्यसोभए धेर अथवा थोर हिमोग्लोविन !!
लेखापानी पुग्दा-पुग्दै लखतरान परेकी जयमाया
हिमोग्लोविन घटेरै हो कि कसो
थलासेमियामा थला परेको उसले सम्झेको छ। """
***** INDEXING in string *****
any programming language count start form 0
x = " Vishal"
print(a [0])
print(a [1])
print(a [2])
we can use this for loop
for character in a:
print(character)
it will display all the character in string