Python programming codes
43 subscribers
25 photos
1 video
83 files
82 links
Uploading All programming codes are updating Daily
ask doubts in comment box 🎁☑️
Download Telegram
#python program to check if the Number is positive, Negative and zero

num=float(input("Enter the Number: "))

if num > 0 :
print("Number is positive")
elif num < 0:
print("Number is negative")
else :
print("Number is zero")
#String operations second one is Replication or Repeated
string = "python" #python wtihout space
repeated_string = string * 3
print(repeated_string) # "pythonpythonpython"


string = "python " #python with space
repeated_string = string * 3
print(repeated_string) # "pythonpythonpython"
How the string does get converted to a number?
Junior
To convert the string into a number the built-in functions are used like int() a constructor. It is a data type that is used like int (‘1’) == 1.

float() is also used to show the number in the format as float(‘1’) = 1.

The number by default are interpreted as a decimal and if it is represented by int(‘0x1’) then it gives an error as ValueError. In this the int(string,base) the function takes the parameter to convert string to number in this the process will be like int(‘0x1’,16) == 16. If the base parameter is defined as 0 then it is indicated by octal and 0x indicates it as a hexadecimal number.

There is function eval() that can be used to convert a string into number but it is a bit slower and present many security risks #python