Python mai hm input le skte hai input function ki help se , input lena mtlb hm saamne se value denge num1 or num2 ki.
num1=input("enter a number:")
num2=input("enter a number:")
print(int(num1)+int(num2))
output
enter a number:56
enter a number:85
141
to hm simply input function ka use krke input le skte hai , lekin ap yaha dekh skte hai ki hmne print statement mai kya print karaya hai , hamne int(num1) + int(num2) likha hai iska mtlb hamne type cast kiya hai to hm type cast kyo kr rahe hai jbki hamne dono value interger value li hai to answer hai jb bhi ham input function ka use krke input lete hai to jo value ham input le rahe hai wo value string mai store hoti hai na ki integer mai isliye ham string ko int mai convert krke addition kr rahe hai.
Escape Sequence character
Escape sequence character basically python mai kuch special character hote hai jaise \n(read as backslash n) jo ki hme text ko next line mai print karane mai help krte hai.
print("Rishabh is go\nod boy")
output
Rishabh is go od boy
--------------------------------------
use of /t
print("Rishabh is go\tod boy")
output
Rishabh is go od boy------------------------------------Python mai bahut saare escape sequence character hote hai aur unke alag alag use hote hai, ye rahi unki listbonus tipstry thisinputprint(5*"I love Python\n")outputI love PythonI love PythonI love PythonI love PythonI love Python
Comments
Post a Comment