Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Strings Formatting Old Way

# ------------------------
# -- Strings Formatting --
# ------------------------

name = "Osama"
age = 36
rank = 10

print("My Name is: " + name)
# print("My Name is: " + name + " and My Age is: " + age)  # Type Error

print("My Name is: %s" % "Osama")
print("My Name is: %s" % name)
print("My Name is: %s and My Age is: %d" % (name, age))
print("My Name is: %s and My Age is: %d and My Rank is: %f" % (name, age, rank))

# %s => String
# %d => Number
# %f => Float

n = "Osama"
l = "Python"
y = 10

print("My Name is %s Iam %s Developer With %d Years Exp" % (n, l, y))

# Control Floating Point Number

myNumber = 10
print("My Number is: %d" % myNumber)
print("My Number is: %f" % myNumber)
print("My Number is: %.2f" % myNumber)

# Truncate String

myLongString = "Hello Peoples of Elzero Web School I Love You All"
print("Message is %s" % myLongString)
print("Message is %.5s" % myLongString)
Comment

PREVIOUS NEXT
Code Example
Python :: linear plot 1D vector for x python 
Python :: calculating expressions with sqrt signs 
Python :: python run only when list is bigger 
Python :: import knn in python jupyter 
Python :: checking time in time range 
Python :: python advanced programs time 
Python :: python two list into dictinaray 
Python :: python Access both key and value using iteritems() Return keys or values explicitly 
Python :: Dizideki en son elemani alma 
Python :: django create view template 
Python :: python developer 
Python :: get random bright hex color python 
Python :: python when to use pandas series, numpy ndarrays or simply python dictionaries 
Python :: tf.get_variable initializer 
Python :: a guide to numpy and pandas 
Python :: data parsing app python 
Python :: strategy forex with python 
Python :: zoom in geopandas polot 
Python :: Python program to read a random line from a file. 
Python :: tf.data.Dataset select files with labels filter 
Python :: right click vs left click pygame 
Python :: Python Create a Local Variable 
Python :: fancy index 
Python :: how can you make a data fram 
Python :: pandas pivot table margins percentage 
Python :: InvalidArgumentError: logits and labels must be broadcastable: logits_size=[16,3] labels_size=[16,2] [[node categorical_smooth_loss/softmax_cross_entropy_with_logits 
Python :: series multiindex values 
Python :: create layer file arcpy 
Python :: how to add strings with entry in tkinter 
Python :: how to count the repeatance of every string in a list python 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =