Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Python Fundamentals: Variables and Data Types

Tech May 15 1

Variable Naming Conventions

  • Names can include letters, digits, and underscores, but must not start with a digit
  • Spaces are not allowed in variable names
  • Names must not conflict with Python keywords
  • Prefer short, descriptive names for clarity

String Handling

Strings in Python are enclosed in either single or double quotes.

Case Manipulation

Use title() to capitalize the first letter of each word in a string.

String Concatenation

Combine strings using the + operator.

Whitespace Management

  • \t inserts a tab character
  • \n inserts a newline character

Trimming Whitespace

  • rstrip() removes trailing whitespace
  • lstrip() removes leading whitespace
  • strip() removes whitespace from both ends

Store the result back in to the varible after modification:

  • Integers (int)
  • Floating-point numbers (float)

Use str() to convert values to string format.

Commenting Practices

  • Single-line comment: # comment here
  • Multi-line comment: enclose within ''' or """

Python Enhancement Principles

Access the guiding principles by importing the hiddan module:

Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than right now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!


</div>

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.