Answers for "how to create a new list in python"

6

how to create a list in python

#creating a list
create_list = ["apple", "banana", "cherry"]
print(create_list)
Posted by: Guest on September-30-2020
6

python list

#Creating lists
my_list = [1, "Hello", 3.4, 0, "World"]
my_nested_list = [['Hello', 'World'],[47,39]]

#Accessing lists
my_list[1] # Hello
my_list[-2] # 0
my_list[:3] # [1, "Hello", 3.4]
my_nested_list[1] #[47,39]
my_nested_list[0][1] # World
Posted by: Guest on May-21-2020
0

creating a list in python

#creating a list in python, and using it to find if the minute right now is odd or even number.

from datetime import datetime #importing a function from a module

import random
import time

odds= [3,5,7,9,11,13,15,17,19,21,23, #variable with a list inside it
       25,27,29,31,33,35,37,39,43,43,
       45,47,49,51,53,55,57,59]

for i in range(5): #start at 0 and loop 5 times

    right_this_minute=datetime.today().minute #variable to store the minute

    if right_this_minute in odds:
        print ("time is odd number")   #if/else statement (conditional statements)

    else:
        print("time is even number")

    wait_time = random.randint(1,60) #generate a random integer and store it in that variable
    time.sleep = wait_time #use the generated variable to sleep for that certain period
print() #print a blank line
Posted by: Guest on June-26-2021

Code answers related to "how to create a new list in python"

Python Answers by Framework

Browse Popular Code Answers by Language