이 블로그 검색

레이블이 Python인 게시물을 표시합니다. 모든 게시물 표시
레이블이 Python인 게시물을 표시합니다. 모든 게시물 표시

2023년 8월 8일 화요일

Summary of Operators in Python

Types of Arithmetic Operators in Python

Symbol Description Return Value
+ Addition Varies depending on the data types
- Subtraction Varies depending on the data types
* Multiplication Varies depending on the data types
/ Division Returns a floating-point value
// Floor Division Returns an integer value
% Modulus Returns a floating-point value
** Exponentiation Varies depending on the data types
and Logical AND Returns True or False
or Logical OR Returns True or False
< Less than Returns True or False
> Greater than Returns True or False
<= Less than or equal to Returns True or False
>= Greater than or equal to Returns True or False
== Equal to Returns True or False

+, -, *, /, //, %, **, <, >, <=, >= Table

A B Result
int int int A + B result
int float float A + B result
int bool-True int A + 1 result
int bool-False int A + 0 result
int None TypeError
int string TypeError
float bool-True float A + 1 result
float bool-False float A + 0 result
float None TypeError
float string TypeError
bool None TypeError
bool string TypeError
None string TypeError

In the early days of computer generation and the inception of programming languages, 1 represented True, and 0 represented False.

== Table

A B Result
int int Boolean result
int float Boolean result
int bool Boolean result
int None Boolean result
int string Boolean result
float bool Boolean result
float None Boolean result
float string Boolean result
bool None Boolean result
bool string Boolean result
None string Boolean result

Unlike Java, this doesn't compare classes. It compares values. Since all are objects, these comparisons are possible.

and, or Truth Tables

A B and or
False False False False
False True False True
True False False True
True True True True

As shown in the table above, "and" and "or" are operations on True and False.

When different data types are used, the "or" operation returns the value of B, while the "and" operation returns the value of A.

2023년 8월 3일 목요일

What is Python Variables

what is Variable

symbol represent some number or String that may change.

data types

scalar and non-scalar both object

scalar

  • int : integer
  • float : real number
  • bool : True or False
  • none : Null

non-scalar

  • String : data values that are made up of ordered sequences of characters, such as "hello world"

How to check data type

print(type(Variable))

addtional infomation

Case-Sensitive

a and A are different variable

Casting

x = str(4)    # "4"
y = int(4)    # 4
z = float(4) # 4.0

2023년 7월 21일 금요일

Setting up Anaconda and PyCharm virtual environments: Step-by-step guide

 

Definition

Anaconda is a package for Python and R languages, providing a convenient conditional free open-source package manager that manages dependencies and distributions.

Since 2020, it has become free only for individual users, universities, non-profit organizations, and small businesses with less than 200 employees. It is now a paid service for government and companies with 200 or more employees.

Reasons to Use Virtual Environments

The reason for using Anaconda is to manage the libraries and versions of Python. By setting up and naming virtual environments, you can easily keep track of the versions and libraries stored in each environment. This makes it convenient to move environments to different locations or reinstall them when needed.

Setting up Anaconda Virtual Environments

Anaconda Installation

  1. Download Anaconda from https://www.anaconda.com/ and install it.
  2. It is recommended to use the default installation path.
  3. If you choose a different installation path, additional configurations may be required based on the IDE you use.
  4. The default path is usually C:\Users\[your computer account name]\anaconda3.

Configuration in PyCharm

When creating a new project in PyCharm, you can create a new virtual environment.

Installing Libraries in PyCharm

Sometimes, the default terminal in PyCharm is PowerShell. In such cases, you need to activate the virtual environment and then install libraries.

To activate the virtual environment:

conda activate (virtual environment name)

Controlling Virtual Environments with Anaconda Console

Opening Anaconda Prompt

Start menu - Anaconda Prompt

Finding Possible Python Versions

conda search python

Creating a Virtual Environment

conda create -n (virtual environment name) python=(desired version)

After that, a list of packages to be installed will be displayed. Type 'y' to proceed with the installation.

Activating the Virtual Environment

If the activation is successful, you will see the virtual environment name instead of (base) in the terminal.

From: (base)current/path>

To: (virtual environment name)current/path>

conda activate (virtual environment name)

Deactivating the Virtual Environment

conda deactivate

Listing Virtual Environments

conda env list

Logic Gate Truth Tables & Definitions

Logic Gate Truth Tables Java Code !A // NOT A&B // AND ~(A&B) // NAND A|B // OR ~(A|B) // XOR A^B // XOR ~(A^B) // XNOR ~A // Inve...