0% found this document useful (0 votes)
6 views2 pages

Python Assignment Swap Membership

The document provides examples of Python programming concepts including augmented assignment operators, swapping two numbers without a temporary variable, and the use of membership operators with lists. It demonstrates how to modify a variable using augmented assignments, swap values of two variables, and check for membership in a list. Additionally, it includes a real-time example of a login check using a membership operator.

Uploaded by

shobithap088
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Python Assignment Swap Membership

The document provides examples of Python programming concepts including augmented assignment operators, swapping two numbers without a temporary variable, and the use of membership operators with lists. It demonstrates how to modify a variable using augmented assignments, swap values of two variables, and check for membership in a list. Additionally, it includes a real-time example of a login check using a membership operator.

Uploaded by

shobithap088
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Programs - Assignment, Swap, Membership

1. Augmented Assignment Operators

x = 10
x += 5 # x = x + 5
print('x += 5:', x)
x -= 3 # x = x - 3
print('x -= 3:', x)
x *= 2 # x = x * 2
print('x *= 2:', x)
x /= 4 # x = x / 4
print('x /= 4:', x)
x %= 3 # x = x % 3
print('x %= 3:', x)

2. Swapping Two Numbers (Without Temp Variable)

a=5
b = 10
print('Before Swap: a =', a, ', b =', b)
a, b = b, a
print('After Swap: a =', a, ', b =', b)

3. Membership Operator - `in` with Lists

colors = ['red', 'green', 'blue']


if 'red' in colors:
print('Red is in the list.')
if 'yellow' not in colors:
print('Yellow is not in the list.')

4. Membership Operator - Real-time Example with Login Check

valid_users = ['admin', 'user1', 'guest']


username = input('Enter your username: ')
if username in valid_users:
print('Access granted')
else:
print('Access denied')

You might also like