new_photo_name = "{:s}/{:03d}-{:%s}". / format(folder_name, counter, original_photo_name)Ans: "{:s}/{:03d}-{:%s}" is a format string and {:s}, {:03d}, {:%s} are format specifiers. Each time that a format specifier occurs in the format string, the corresponsing argument of the format method is entered in the output string. {:s} means that a str object will be included; {:03d} means that a decimal number with field width 3 with leading zeros will be included. The resulting string for the eiffel tower in paris is "paris/001-eiffel-tower.jpg"
d = { }
d["age"] = 35 d["id"] = 1234
print(len(d))
for key in d: print(key, ":", d[key])
Variable name | name | gender | age |
---|---|---|---|
child_alice | "Ally" | "F" | 11 |
child_robert | "Bob" | "M" | 9 |
child_susan | "Sue" | "F" | 10 |
Reference: docs.oracle.com/javase/tutorial/java/concepts/object.html
# Create a Child class with no extra structure. # pass means that there is no body for the class. class Child: pass # Create first Child object. child_alice = Child( ) child_alice.name = "Ally" child_alice.gender = "F" child_alice.age = 11 # Create second Child object. child_robert = Child( ) child_robert.name = "Bob" child_robert.gender = "M" child_robert.age = 9 # Create third Child object. child_susan = Child( ) child_susan.name = "Sue" child_susan.gender = "F" child_susan.age = 10 # Print Child information. print(child_susan.name) print(child_alice.age) print(child_robert.gender)
s = "elephant" print(s.upper( )) print(s.count("e")) print(s.find("ph"))
name age is_sleeping (True, False) was_recently_fed (true, false) mood ("smiling", "crying") diaper_state (clean, soiled)
drink smile sleep move_arms kick cry wet_diaper
# Create three str objects: s1 = "elephant" s2 = str(3087) s3 = str( ) # Create three int objects: n1 = 3087 n2 = int("873") n3 = int( ) # Create three list objects: lst1 = [4, 2, 3, 1] lst2 = list("dog") lst3 = list( )
n = len(s)
t = s.upper( )