python list in java code example

Example 1: list() python

# empty list
print(list())
#-->[]

# vowel string
vowel_string = 'aeiou'
print(list(vowel_string))
#-->['a', 'e', 'i', 'o', 'u']

# vowel tuple
vowel_tuple = ('a', 'e', 'i', 'o', 'u')
print(list(vowel_tuple))
#-->['a', 'e', 'i', 'o', 'u']

# vowel list
vowel_list = ['a', 'e', 'i', 'o', 'u']
print(list(vowel_list))
#-->['a', 'e', 'i', 'o', 'u']

Example 2: 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