NoSleepCreative Wiki
  • Welcome to NoSleepCreative
  • After Effects
    • Getting Started with Expressions
    • Expressions & Snippets
      • JSX Cheatsheet
      • Expression Troubleshooting
      • Utilities
      • Shape & Mask
      • Type & Text
    • Cookbook
      • Algorithmic
      • Random properties
      • Harmonic Motion
      • Staggering
      • Tessellation & Tiling
      • Type animators
      • Speed lines
      • Radial Array
      • Orb & Trails
      • Shading & Texturing
      • Responsive
      • Automation
      • Setup & Rigs
    • Getting started with Scripting
    • Scripting
      • Utilities
      • Master Properties
    • ScriptUI
  • Studio Ops
    • Tooling
    • Toolkitting
    • Knowledge Base
    • Naming Convention
    • DAM
  • Cinema 4D
    • Formulas
    • Python Cheat Sheet
      • For Artists
      • Maya Environment
      • Maya snippets
      • VSFX 705
    • Cookbook
  • Info
    • About
    • Portfolio
    • Course
    • YouTube
    • Gumroad
    • GitHub
  • Dev
    • archive
      • Webscraping
      • Google Sheets Formulas
      • SQL
      • Terminal
      • C++
      • Unreal Engine
      • Concert Visualization
      • Dome-projection
      • UI UX
      • Professional Etiquettes
      • Woes
      • How to get better
        • Portfolio / Showreel
        • Design with cooking
      • Media theories
        • Post Cinematic Affect
        • Marxism, Reproduction and Aura
        • Heuristics & Authorship
        • 02 Semiotics
        • 3 Process?
        • 05
        • 06 Technology & Mediation
        • Formalism
        • Simulation
        • The Gaze & Media Critique
        • Import
        • 10-12
      • Recommended books
        • 🔴Things I learned
      • Mac Superuser
        • Applescript
      • InDesign
      • Illustrator
      • Blender
      • Premiere Pro
      • Mathematics
        • Probability
        • Linear Algebra
      • Shader Dev
      • Getting Started with After Effects
        • Best Practices
        • Pimping up AE
        • Environment
      • Houdini
        • Cheatsheet
        • Cookbook
        • Techniques
        • Dynamic
        • Rendering & Lighting
        • Animation
        • Particles
        • Others
          • Modeling
          • Fluids - Pyro & Smoke
          • Rendering
      • REGEX
    • Sandbox
      • Nexrender
        • Terminology
        • Project Files Preparation
Powered by GitBook
On this page
  • Getting Started
  • Class

Was this helpful?

  1. Cinema 4D

Python Cheat Sheet

Syntax/Concept
Example
Explanation

Print statement

print("Hello, world!")

Outputs the given text to the console

Comments

# This is a comment

Comments are ignored by Python and are used to document code

Multiline comment

"""

This is a multiline comment.

It can span multiple lines without the need for multiple comment symbols.

You can use it to document your code or temporarily disable a block of code.

""”

Variables

x = 5

Variables are used to store data and can be assigned and reassigned values

Data types

int, float, string, bool, list, tuple, dict, set

Different types of data that can be stored in variables

Numeric operations

+, -, *, /, %, **

Operators used for arithmetic operations

Comparison operators

==, !=, >, <, >=, <=

Operators used to compare values

Logical operators

and, or, not

Operators used to combine and manipulate boolean values

Conditional statements

if, elif, else

Statements used to conditionally execute code

Loops

for, while

Statements used to iterate over a sequence of data

Functions

def my_func():, return

Blocks of code that can be called and returned

Lambda functions

lambda x: x + 1

Anonymous functions used for simple operations

Classes

class MyClass:, def init(self):, self

Used to define custom data types and associated functions

List methods

append(), extend(), insert(), remove(), pop(), index(), count(), sort(), reverse()

Methods used to manipulate lists

Tuple methods

count(), index()

Methods used to manipulate tuples

Dictionary methods

keys(), values(), items(), get(), update(), pop(), popitem(), clear()

Methods used to manipulate dictionaries

Set methods

add(), remove(), discard(), pop(), clear(), union(), intersection(), difference(), symmetric_difference()

Methods used to manipulate sets

Getting Started

  • Setting up a Python Development Environment

    • Requirements: syntax highlighting, beautification, linter, IntelliSense: list members, parameter info, quick info, autocompletion,

Class

  • Why? Logically group our data and functions that we can easily reuse or build upon

  • Terminology

    • Attributes and methods - functions that is associated with class

    • A class is a blueprint for creating instances

class Employee:
    pass 

# instances of a Employee classes
emp_1 = Employee()
emp_2 = Employee()
s
# unique data 
#manually variable setting - prone to human error
emp_1.first = 'Corey'
emp_1.last = 'Scafer'
emp_1.email = 'cScafer@company.com'
emp_1.pay = '50000'

emp_2.first = 'Test'
emp_2.last = 'User'
emp_2.email = 'testUser@company.com'
emp_21.pay = '60000'
######

class Employee:
    def __init__(self,first,last,pay):
        #set instance variable 
        self.first = first
        self.last = last
        self.pay =pay
        self.email = first +'.' + last + '@company.com'
        
    # each method within a class automatically takes the insance as the first argument
    # and we always call that self
    def fullname(self)
        return '{}{}'.format(self.first,self.last)
    
# better solution: runs init automatically 
emp_1 = Employee('Corey','Scafer',50000)
emp_2 = Employee('Test','User',60000)

print(emp_1.email)
print(emp_2.email)

# running actions
    #manually 
    print('{}{}'.format)emp_1.first,emp_1,last))
    
    # better 
    print(emp_1.fullname()) # notice the parenthesis as it is a method

#notes
#classes are kinda like function
# remember to put self in methods in class
    emp_1.fullname() is same as Employee.fullname(emp_1))
PreviousFormulasNextFor Artists

Last updated 1 year ago

Was this helpful?

Corey Schafer, 6 parts

Object-Oriented Programming
Corey Schafer