my_keys=('a','b','c') # using a tuple
my_values=('ONe','Two','Three')
my_dict=dict.fromkeys(my_keys,my_values)
print(my_dict)
Output is here
{'a': ('ONe', 'Two', 'Three'), 'b': ('ONe', 'Two', 'Three'),
'c': ('ONe', 'Two', 'Three')}
my_keys=('a','b','c') # using a tuple
my_dict=dict.fromkeys(my_keys)
print(my_dict)
Output
{'a': None, 'b': None, 'c': None}
my_keys=('a','b','c') # using a tuple
my_values=('One')
my_dict=dict.fromkeys(my_keys,my_values)
print(my_dict)
Output
{'a': 'One', 'b': 'One', 'c': 'One'}
my_keys=range(1,6) # using a range to get sequence of keys
my_dict=dict.fromkeys(my_keys)
print(my_dict)
Output
{1: None, 2: None, 3: None, 4: None, 5: None}
We can assign value to any key
my_dict[2]='Two'
print(my_dict)
Output
{1: None, 2: 'Two', 3: None, 4: None, 5: None}
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.