🔷 Python Strings – Single, Double & Multiline Strings are used to store text data in Python. They are written inside single quotes (' ') or double quotes (" "). 🔹 1️⃣ Single Quotes & Double Quotes Both single and double quotes work the same in Python. ▶ Example print('hi') print("hi") ✔ Output: hi 🔹 2️⃣ Using Quotes Inside Strings We can use single quotes inside double quotes and vice versa. ▶ Example print("my programming language is 'python'") print('my programming language is "python"') ✔ Output: my programming language is 'python' my programming language is "python" 🔹 3️⃣ Storing Strings in Variables We can store strings in variables. ▶ Example name = 'neena' print(name) ✔ Output: neena 🔹 4️⃣ Multiline Strings (Triple Quotes) To write strings in multiple lines, we use triple quotes (""" """). ▶ Example a = """ qwer aasfghjkk zxvnm """ print(a) ✔ Output: qwer aasfghjkk zxvnm 📌 Learning strings is important for working with text, messages, and user input. #Python #PythonStrings #LearningPython #DataAnalyticsJourney #CodingLife
Python Strings: Single, Double & Multiline Basics
More Relevant Posts
-
🐍 Basic #Python Variables – The Foundation of Every Python Program If you’re starting your journey with Python, understanding variables and data types is your first major milestone. Variables are containers for storing data. In Python, they are simple to declare but incredibly powerful in how they shape your programs. Here’s a quick breakdown of the core data types every beginner should know: 🔢 Integer Whole numbers without decimals. Example: 10, -5 🔹 Float Numbers with decimal points. Example: 4.5, -0.4 ✅ Boolean Represents logical values: True or False Essential for decision-making in programs. 📦 List An ordered collection that can store multiple data types. Example: [22, "Hello world", 3.14, True] 🔁 Tuple Similar to a list but immutable (cannot be changed after creation). Example: (7, 5, 8) 🎯 Set An unordered collection of unique elements. Example: {7, 5, 8} 🗂 Dictionary Stores data in key–value pairs. Example: {"name": "Alice", "age": 25} 🚫 None Represents the absence of a value. Mastering these fundamental data types builds the groundwork for writing efficient Python code. Every advanced concept — from data structures to machine learning — relies on these basics. Strong foundations create strong developers. #Python #Programming #Coding #SoftwareDevelopment #LearnPython #TechSkills
To view or add a comment, sign in
-
-
#Day 11 /50DaysChallenge #Strings in Python ✨String: A string is a collection of characters inside quotes. Example: name = "Python" ✅ String Indexing text = "Python" print(text[0]) # P print(text[3]) # h ✅ String Slicing text = "Python" print(text[0:3]) # Pyt print(text[2:6]) # thon ✅ String Methods (Important) text = "python programming" print(text.upper()) # PYTHON PROGRAMMING print(text.lower()) # python programming print(text.title()) # Python Programming print(text.replace("python", "java")) Task: Take a string from user and print: - Length - Uppercase - Lowercase - Reverse string Code: text = input("Enter a string: ") print("Length:", len(text)) print("Uppercase:", text.upper()) print("Lowercase:", text.lower()) print("Reverse:", text[::-1]) ✅ Example Output: Enter a string: Python Length: 6 Uppercase: PYTHON Lowercase: python Reverse: nohtyP #50Dayschallenge #coding #pythonbascis #ece #bve
To view or add a comment, sign in
-
🥰 Python Operators: -> Operators are the building blocks of every Python program. Here are all 7 types : 1) ➕ Arithmetic — Perform basic mathematical calculations. + − * / // % ** → 10 // 3 = 3 | 2 ** 8 = 256 | 10 % 3 = 1 2) ⚖️ Relational — Compare two values and return True or False. == != > < >= <= → 5 == 5 → True | 7 > 4 → True 3) 🧠 Logical — Combine multiple conditions using Boolean logic. and, or, not → age > 18 and score > 80 → True only if BOTH are met 4) ⚡ Bitwise — Work directly on binary (bit-level) representations of integers. & | ^ ~ << >> → 5 & 3 = 1 | 5 | 3 = 7 | 5 << 1 = 10 5) ✍️ Assignment — Assign values to variables, with shortcuts for updating them. = += -= *= /= //= %= **= → x += 3 is just a shorter way to write x = x + 3 6) 🔍 Membership — Check whether a value exists within a sequence. in, not in → Works with lists, strings, tuples, sets & dictionaries 7) Identity — Check if two variables point to the same object in memory. is, is not → ⚠️ == checks VALUES. is checks MEMORY LOCATION
To view or add a comment, sign in
-
Accessing Dictionary Values Safely in Python Dictionaries are powerful data structures in Python that store data as key-value pairs, allowing for efficient access. Accessing items correctly is essential, especially when the existence of a key is uncertain. The most straightforward way to retrieve a value is by using the key directly, as shown with `person['name']`. This method works seamlessly, but if a key does not exist, Python raises a `KeyError`, potentially leading to runtime errors. That's where the `get` method becomes advantageous. It allows for safe retrieval; if the key isn’t found, it returns `None` instead of causing a crash. Another valuable feature of the `get` method is its ability to specify a default return value. In our example, when looking for 'country', if it doesn’t exist, we can have it return 'Unknown'. This ability is particularly useful in real-world applications, ensuring that our code remains robust and gracefully handles missing data. Understanding the difference between direct access and the `get` method becomes crucial when working with dynamic datasets or user-generated content, where missing keys are commonplace. The choice of method can significantly impact how well your code handles such situations. Quick challenge: In what scenario would you prefer to use the `get` method over direct key access when dealing with dictionaries? #WhatImReadingToday #Python #PythonProgramming #Dictionaries #PythonTips #Programming
To view or add a comment, sign in
-
-
Day 3- Python Programming Today I learned the basic data types in Python and how variables work. 🔹 Data Types covered: • Integer – whole numbers (e.g., 5) • Decimal / Float – numbers with decimals (e.g., 3.14) • Single Character – stored using string (e.g., 'A') • String – text data (e.g., "Hello, World!") • Boolean – logical values (True / False) 🔹 Variables in Python: ✔ Variables are used to store data values ✔ Variables can change their value during execution Example: score = 10 → score = 20 Building a strong foundation in Python by learning one concept at a time
To view or add a comment, sign in
-
-
🔷 Python Strings Strings are used to store text data in Python. They are written inside single quotes (' ') or double quotes (" "). 🔹 Creating Strings • Strings can be written using single quotes or double quotes • 'Hello' and "Hello" are treated the same in Python 🔹 Displaying Strings • String values can be displayed using the print() function • This is called printing a string literal 🔸 Example • print("Hello") • print('Hello') ▶ Output: Hello 🔹 Key Point ✔ Strings are immutable (cannot be changed) ✔ Used to store and work with text data Strings are widely used in Python for messages, input, and data processing. #Python #PythonStrings #ProgrammingBasics #LearningJourney #Upskilling
To view or add a comment, sign in
-
🐍 Did you know? In Python, descriptors let you take full control over class attributes. They allow you to customize behavior when instance variables are accessed, modified, or deleted. What are Descriptors? A descriptor is a class that implements one or more of the following special methods: 1. Non-data descriptor Does not override instance dictionary values. Method: __get__(self, instance, owner) 2. Data descriptor Overrides instance dictionary values. Methods: __set__(self, instance, value) __delete__(self, instance) Example: class PositiveInteger: def __set_name__(self, owner, name): print(f"Setting name {name} for {owner}") self.name = name def __get__(self, instance, owner): print("Getting value...") return instance.__dict__.get(self.name, 0) def __set__(self, instance, value): if not isinstance(value, int): raise TypeError(f"{self.name} must be an integer.") if value <= 0: raise ValueError(f"{self.name} must be a positive integer.") print(f"Setting {self.name} to {value}...") instance.__dict__[self.name] = value def __delete__(self, instance): print(f"Deleting {self.name}...") del instance.__dict__[self.name] class Product: quantity = PositiveInteger() #Python #PythonProgramming #PythonDevelopers #SoftwareEngineering #Programming
To view or add a comment, sign in
-
-
Most of us write Python without thinking about what's happening under the hood. But understanding memory management can be the difference between a script that scales. Here's what every Python developer should know: Python handles memory automatically — but not magically. CPython uses reference counting as its primary mechanism. Every object tracks how many references point to it. When that count hits zero, the memory is freed. Simple, elegant, and mostly invisible. But reference counting has a blind spot: circular references. If object A references B and B references A, neither count ever reaches zero. That's where Python's cyclic garbage collector steps in — it periodically detects and cleans up these cycles. Practical tips I've learned the hard way: → Use del to explicitly remove references you no longer need in long-running processes → Be careful with large objects in global scope — they live for the entire program lifetime → Use generators instead of lists when processing large datasets — they're lazy and memory-efficient → Profile before optimizing. Tools like tracemalloc, memory_profiler, and objgraph are your best friends → Watch out for closures accidentally holding onto large objects The bigger picture: Python's memory model is designed to let you focus on solving problems, not managing pointers. But when you're building data pipelines, web services, or ML workflows at scale, knowing these internals pays dividends. What memory-related bugs have caught you off guard in Python? Drop them in the comments #Python #SoftwareEngineering #Programming #BackendDevelopment #PythonTips
To view or add a comment, sign in
-
-
List vs Generator in Python — A Small Change That Can Save Significant Memory While working with large datasets, I explored how Python stores 10,000 numbers using a List and a Generator — and the memory difference was surprisingly noticeable. Here’s what happens behind the scenes: 🔹 List: - A list stores all values in memory at once. - When created using list comprehension, Python generates and stores every element immediately. This allows fast access but increases memory usage. 🔹 Generator: - A generator works differently. - Instead of storing all values, it produces elements only when required. This approach, known as lazy evaluation, helps reduce memory consumption significantly. Key Observations: • Lists store complete data in memory. • Generators produce values on demand. • Memory difference grows as dataset size increases. Choosing between a list and a generator may seem like a small design decision, but it can greatly improve scalability and memory efficiency in Python applications. 📌 Save this if you work with large datasets or performance-sensitive systems. ⚠️ Note: Memory usage may vary depending on system architecture and Python version. #Python #LearnPython #PythonTips #Programming #SoftwareEngineering #PerformanceOptimization #PythonDeveloper
To view or add a comment, sign in
-
-
nderstanding Tuples in Python Tuples are one of Python’s core data structures — simple, powerful, and immutable. 📌 Key Highlights: ✔️ Creating tuples (including single-element and empty tuples) ✔️ Tuple unpacking (`x, y = coords`) ✔️ Using `*` for extended unpacking ✔️ Built-in methods like `.index()` and `.count()` ✔️ Introduction to `namedtuple` for more readable and structured data Unlike lists, tuples are immutable, which makes them faster and safer when you don’t want data to change. 💡 Tuples are commonly used for: * Storing fixed data * Returning multiple values from functions * Representing coordinates or structured records Mastering tuples helps you write cleaner and more efficient Python code. #Python #Programming #DataStructures #Coding #PythonLearning #Developer #100DaysOfCode
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development