Python list and tuples and commas

1. List with commas

email_addresses = [
    '[email protected]',
]
for email_address in email_addresses:
    print email_address
#output=> [email protected]

2. List without commas

email_addresses = [
    '[email protected]'
]
for email_address in email_addresses:
    print email_address
#output=> [email protected]

3. Tuple with comma

email_addresses = (
    '[email protected]',
)
for email_address in email_addresses:
    print email_address
#output=> [email protected]

4. Tuples without commas

email_addresses = (
   '[email protected]'
)
for email_address in email_addresses:
    print email_address
#output=>  
 t
 e
 s
 t
 @
 g
 m
 a
 i
 l
 . 
 c
 o
 m

It is output character by character, probably because it is regarded as a character string.

5. Multi-element tuple

email_addresses = (
    '[email protected]',
    '[email protected]'
)
for email_address in email_addresses:
    print email_address
    
#output=> [email protected]
       [email protected]

comment

When I changed what was in the state of 5 to 4, it was a bug, so I was curious and investigated.

It seems like this.

foo = "abc"
bar = ("abc")
foo == bar
 #↑ True

Recommended Posts

Python list and tuples and commas
Python list comprehensions and generators
[Python] list
Difference between list () and [] in Python
Python basics: list
Python comprehension (list and generator expressions) [additional]
Python data structure and internal implementation ~ List ~
Difference between append and + = in Python list
list and sum
list and numpy
Python> Comprehension / Comprehension> List comprehension
[Python Iroha] Difference between List and Tuple
Python list manipulation
How to clear tuples in a list (Python)
List of Python code to move and remember
What are python tuples and * args after all?
Sorted list in Python
Python Exercise 2 --List Comprehension
List of python modules
Python> list> extend () or + =
Python and numpy tips
[Python] pip and wheel
Batch design and python
Python iterators and generators
Python list comprehension speed
Filter List in Python
Python packages and modules
Vue-Cli and Python integration
python unittest assertXXX list
Ruby, Python and map
Python3 | Lists, Tuples, Dictionaries
Python> Tuples versus Lists
Python lists, tuples, dictionaries
Python3 List / dictionary memo
[Memo] Python3 list sort
OpenCV3 Python API list
Python error list (Japanese)
Python and Ruby split
List find in Python
Python3, venv and Ansible
Python asyncio and ContextVar
Python exception class list
How tuples work | Python
Initialize list with python
Mayungo's Python Learning Note: List of stories and links
Implemented List and Bool in Python and SQLite3 (personal note)
List of Python libraries for data scientists and data engineers
[Python] How to sort dict in list and instance in list
Save lists, dictionaries and tuples to external files python
Programming with Python and Tkinter
Python hand play (two-dimensional list)
Encryption and decryption with Python
Python: Class and instance variables
3-3, Python strings and character codes
Python list, for statement, dictionary
Python 2 series and 3 series (Anaconda edition)
Python and hardware-Using RS232C with Python-
Summary of Python3 list operations
Python on Ruby and angry Ruby on Python
Python real division (/) and integer division (//)
[Python] Convert list to Pandas [Pandas]