codewithronny logo
codewithronny logo
  • Category
    • Adsense
    • Blog
    • Boilerplate
    • CodeWithRonny
    • Course Review
    • How to
    • HTML Tutorial
    • JavaScript
      • JavaScript Tutorial
    • Laravel
    • Machine Learning
      • Machine Learning Tutorial
    • MySQL
      • MySQL Tutorial
    • Networking
    • PHP Tutorial
    • Python
      • Data Structure Using Python
      • Python Interview Question
      • Python Tutorial
    • Python Coding Interview Practice
    • Server
      • Share Hosting
    • Tech Celebrity
    • Web Technologies and Development
    • Wordpress
      • Theme
  • Information
    • Contact Us
    • About Us
    • Privacy Policy
    • Terms
    • Disclaimer
  • Code Editor
    • HTML Code Editor
    • Python Code Editor
Python Tutorial
Python TutorialPython VariablesVariables Name in PythonPython Variables - Multiple Value AssignmentPython Data Types

Python Variables – Multiple Value Assignment


Many Values to Multiple Variables

In Python, you can assign multiple values in a single line. Here are a few methods.

a, b, c = "code", "with", "ronny"

print(a) #code
print(b) #with
print(c) #ronny

One Value to Multiple Variables

In Python, you can assign one values to multiple variables in a single line. Here are a few methods.

a = b = c = "code"

print(a) #code
print(b) #code
print(c)#code

Unpacking

Assigning all the value into variables is called unpacking. There is alots of methods

Method 1: Unpacking Using Lists

# Using a list
values = [10, 20, 30]
a, b, c = values


print(a) #10
print(b) #20
print(c) #30

Method 2: Unpacking Using Tuples

# Using a tuple
values = (40, 50, 60)
a, b, c = values


print(a) #40
print(b) #50
print(c) #60

Method 3: Unpacking Using the Asterisk * (Splat) Operator

# Using the splat operator to gather values into a list
values = [100, 110, 120]
x = [*values]

print(x) #[100, 110, 120]
# Using the splat operator to gather values into a list
values = [100, 110, 120, 130, 140, 150, 160, 170]
x, *y, z = values

print(x) #100
print(*y) #110 120 130 140 150 160
print(z) #170
# Using the splat operator to gather values into a list
values = [100, 110, 120, 130, 140, 150, 160, 170]
x, y, *z = values

print(x) #100
print(y) #110 
print(z) #120 130 140 150 160 170






codewithronny logo
codewithronny logo

A Tutorial Cafe

  • Twitter
  • Facebook
  • Instagram
  • Linkedin
  • Linkedin
Company
    About Us
  • Contact Us
  • Career
Community
    Documentation
  • Faq
  • Sitemap
Explore
    Terms & Conditions
  • Privacy policy
  • Disclaimer
  • Affiliate Disclosure
  • Become an Author
  • How to guide
Contact


Copyrights ©2024 CodeWithRonny
  • GlobeLanguage Chevron
    • English
    • Hindi
  • Terms of use
  • Cookies
  • Sitemap